2021-09-12 13:28:44 +02:00
|
|
|
const nonHumanMeasurements = require('./non-human-measurements.js')
|
2020-03-15 16:34:56 +01:00
|
|
|
/*
|
|
|
|
* This runs unit tests for pattern sampling
|
|
|
|
* It expects the following:
|
|
|
|
*
|
|
|
|
* @param string me: Name of the pattern (eg 'aaron')
|
|
|
|
* @param object Pattern: pattern constructor
|
|
|
|
*
|
|
|
|
* @param object expect: Imported chai.expect
|
|
|
|
* @param object models: Imported @freesewing/models
|
|
|
|
* @param object patterns: Imported @freesewing/pattern-info
|
|
|
|
*/
|
2021-09-12 14:03:25 +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
|
|
|
const testPatternSampling = (design, Pattern, expect, models, patterns) => {
|
2021-09-12 13:28:44 +02:00
|
|
|
// Load non-human measurements
|
|
|
|
const nonHuman = nonHumanMeasurements(models)
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// Figure out whether this is a with(out)breasts pattern
|
|
|
|
const breasts = (patterns.withBreasts.indexOf(design) === -1) ? false : true
|
|
|
|
|
|
|
|
const ourModels = models
|
|
|
|
[breasts ? 'withBreasts' : 'withoutBreasts']
|
|
|
|
const measurements = ourModels
|
|
|
|
[breasts ? 'size34' : 'size42']
|
|
|
|
|
2020-03-19 10:44:29 +01:00
|
|
|
if (['rendertest', 'tutorial', 'examples'].indexOf(design) === -1) {
|
|
|
|
/*
|
|
|
|
* Sample different measurements
|
|
|
|
*/
|
|
|
|
it('Sample different measurements:' , () => true)
|
|
|
|
for (let measurement of Pattern.config.measurements) {
|
|
|
|
it(` Sample ${measurement}:` , () => {
|
|
|
|
expect(doesItSample(new Pattern({
|
|
|
|
sample: {
|
|
|
|
type: 'measurement',
|
|
|
|
measurement
|
|
|
|
},
|
|
|
|
measurements
|
|
|
|
}))).to.equal(true)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (['rendertest', 'tutorial', 'examples'].indexOf(design) === -1) {
|
|
|
|
/*
|
|
|
|
* Sample different options
|
|
|
|
*/
|
|
|
|
it('Sample different options:' , () => true)
|
|
|
|
for (let option in Pattern.config.options) {
|
|
|
|
it(` Sample ${option}:` , () => {
|
|
|
|
expect(doesItSample(new Pattern({
|
|
|
|
sample: {
|
|
|
|
type: 'option',
|
|
|
|
option
|
|
|
|
},
|
|
|
|
measurements
|
|
|
|
}))).to.equal(true)
|
|
|
|
})
|
|
|
|
}
|
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
|
|
|
|
*/
|
2021-09-11 15:50:32 +02:00
|
|
|
it('Sample pattern for size range:' , () => {
|
2020-03-15 16:34:56 +01:00
|
|
|
expect(doesItSample(new Pattern({
|
|
|
|
sample: {
|
2020-03-19 10:44:29 +01:00
|
|
|
type: 'models',
|
|
|
|
models: ourModels,
|
2020-03-15 16:34:56 +01:00
|
|
|
},
|
|
|
|
measurements
|
|
|
|
}))).to.equal(true)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
/*
|
|
|
|
* Sample pattern for dolls & giants
|
|
|
|
*/
|
|
|
|
for (const type of ['dolls', 'giants']) {
|
|
|
|
it(`Sample pattern for ${type}:` , () => {
|
|
|
|
expect(doesItSample(new Pattern({
|
|
|
|
sample: {
|
|
|
|
type: 'models',
|
|
|
|
models: nonHuman[breasts ? 'withBreasts' : 'withoutBreasts'][type]
|
|
|
|
},
|
|
|
|
measurements
|
|
|
|
}))).to.equal(true)
|
|
|
|
})
|
|
|
|
}
|
2021-09-11 15:50:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-15 16:34:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = testPatternSampling
|