2022-08-27 09:27:35 +02:00
|
|
|
import designs from "../../config/software/designs.json" assert { type: 'json' }
|
2022-09-06 16:52:28 +02:00
|
|
|
import { adult, doll, giant } from '@freesewing/models'
|
2022-09-01 08:44:12 +02:00
|
|
|
import { getFamily } from './config.mjs'
|
2022-08-25 11:52:34 +02:00
|
|
|
import chai from 'chai'
|
|
|
|
|
|
|
|
const expect = chai.expect
|
2022-08-27 09:27:35 +02:00
|
|
|
|
|
|
|
// Some patterns are deprecated and won't support more stringent doll/giant tests
|
|
|
|
const deprecated = ['theo']
|
|
|
|
|
2020-03-15 16:34:56 +01:00
|
|
|
/*
|
|
|
|
* This runs unit tests for pattern sampling
|
|
|
|
* It expects the following:
|
|
|
|
*
|
2022-08-27 09:27:35 +02:00
|
|
|
* @param object Pattern: Pattern constructor
|
2022-08-25 11:52:34 +02:00
|
|
|
* @param boolean log: Set to true to log errors
|
2020-03-15 16:34:56 +01:00
|
|
|
*/
|
2022-08-27 09:27:35 +02:00
|
|
|
export const testPatternSampling = (Pattern, log=false) => {
|
2021-09-12 14:03:25 +02:00
|
|
|
|
2022-08-27 09:27:35 +02:00
|
|
|
const pattern = new Pattern()
|
|
|
|
const config = pattern.getConfig()
|
2022-09-01 08:44:12 +02:00
|
|
|
const design = pattern.config.data.name
|
2022-08-27 09:27:35 +02:00
|
|
|
const family = getFamily(design)
|
|
|
|
const parts = pattern.getPartList()
|
2021-09-12 14:03:25 +02:00
|
|
|
|
2020-03-15 16:34:56 +01:00
|
|
|
// Helper method to try/catch pattern sampling
|
2021-09-04 17:46:44 +02:00
|
|
|
const doesItSample = (pattern, log=false) => {
|
|
|
|
try {
|
|
|
|
pattern.sample()
|
|
|
|
if (pattern.events.error.length < 1) return true
|
|
|
|
if (log) console.log(pattern.events.error)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
if (log) console.log(err)
|
|
|
|
return false
|
|
|
|
}
|
2020-03-15 16:34:56 +01:00
|
|
|
}
|
|
|
|
|
2020-03-19 10:44:29 +01:00
|
|
|
if (['rendertest', 'tutorial', 'examples'].indexOf(design) === -1) {
|
|
|
|
/*
|
|
|
|
* Sample different measurements
|
|
|
|
*/
|
2022-08-31 17:54:37 +02:00
|
|
|
describe('Sample measurements:' , () => {
|
|
|
|
for (const measurement of config.measurements || []) {
|
|
|
|
it(` Sample ${measurement}:` , () => {
|
|
|
|
expect(doesItSample(new Pattern({
|
|
|
|
sample: {
|
|
|
|
type: 'measurement',
|
|
|
|
measurement
|
|
|
|
},
|
2022-09-06 16:52:28 +02:00
|
|
|
measurements: adult.cisFemale["36"]
|
2022-08-31 17:54:37 +02:00
|
|
|
}), log)).to.equal(true)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
2020-03-19 10:44:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (['rendertest', 'tutorial', 'examples'].indexOf(design) === -1) {
|
|
|
|
/*
|
|
|
|
* Sample different options
|
|
|
|
*/
|
2022-08-31 17:54:37 +02:00
|
|
|
describe('Sample options:' , () => {
|
|
|
|
for (const option in Pattern.config.options) {
|
|
|
|
if (typeof Pattern.config.options[option] === 'object') {
|
|
|
|
it(` Sample ${option}:` , () => {
|
|
|
|
expect(doesItSample(new Pattern({
|
|
|
|
sample: {
|
|
|
|
type: 'option',
|
|
|
|
option
|
|
|
|
},
|
2022-09-06 16:52:28 +02:00
|
|
|
measurements: adult.cisFemale["36"]
|
2022-08-31 17:54:37 +02:00
|
|
|
}), log)).to.equal(true)
|
|
|
|
})
|
|
|
|
}
|
2022-06-30 12:09:35 +02:00
|
|
|
}
|
2022-08-31 17:54:37 +02:00
|
|
|
})
|
2020-03-15 16:34:56 +01:00
|
|
|
}
|
|
|
|
|
2020-03-19 10:44:29 +01:00
|
|
|
if (['rendertest', 'tutorial', 'examples'].indexOf(design) === -1) {
|
|
|
|
/*
|
|
|
|
* Sample pattern for different models
|
|
|
|
*/
|
2022-09-06 16:52:28 +02:00
|
|
|
describe(`Sample human measurements:` , () => {
|
|
|
|
for (const type of ['cisFemale', 'cisMale']) {
|
|
|
|
it(`Sample pattern for adult ${type} size range:` , () => {
|
2022-08-31 17:54:37 +02:00
|
|
|
expect(doesItSample(new Pattern({
|
|
|
|
sample: {
|
|
|
|
type: 'models',
|
2022-09-06 16:52:28 +02:00
|
|
|
models: adult[type],
|
2022-08-31 17:54:37 +02:00
|
|
|
},
|
|
|
|
}), log)).to.equal(true)
|
|
|
|
})
|
|
|
|
}
|
2020-03-15 16:34:56 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-09-11 15:50:32 +02:00
|
|
|
if (['rendertest', 'tutorial', 'examples'].indexOf(design) === -1) {
|
2021-09-12 14:03:25 +02:00
|
|
|
if (deprecated.indexOf(design) === -1) {
|
|
|
|
/*
|
2022-09-06 16:52:28 +02:00
|
|
|
* Sample pattern for doll & giant
|
2021-09-12 14:03:25 +02:00
|
|
|
*/
|
2022-09-06 16:52:28 +02:00
|
|
|
for (const family of ['doll', 'giant']) {
|
|
|
|
describe(`Sample ${family} measurements:` , () => {
|
|
|
|
for (const type of ['cisFemale', 'cisMale']) {
|
2022-08-31 17:54:37 +02:00
|
|
|
it(`Sample pattern for ${family} ${type} size range:` , () => {
|
|
|
|
expect(doesItSample(new Pattern({
|
|
|
|
sample: {
|
|
|
|
type: 'models',
|
2022-09-06 16:52:28 +02:00
|
|
|
models: family === 'doll'
|
|
|
|
? doll[type]
|
|
|
|
: giant[type]
|
2022-08-31 17:54:37 +02:00
|
|
|
},
|
|
|
|
}), log)).to.equal(true)
|
|
|
|
})
|
|
|
|
}
|
2021-09-12 14:03:25 +02:00
|
|
|
})
|
|
|
|
}
|
2021-09-11 15:50:32 +02:00
|
|
|
}
|
|
|
|
}
|
2020-03-15 16:34:56 +01:00
|
|
|
}
|
|
|
|
|