chore: Added more unittests for patterns
This commit is contained in:
parent
13c4cbd779
commit
926e921582
39 changed files with 818 additions and 6 deletions
81
tests/patterns/sampling.js
Normal file
81
tests/patterns/sampling.js
Normal file
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* 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
|
||||
*/
|
||||
const testPatternSampling = (design, Pattern, expect, models, patterns) => {
|
||||
|
||||
// Helper method to try/catch pattern sampling
|
||||
const doesItSample = pattern => {
|
||||
try {
|
||||
pattern.sample()
|
||||
return true
|
||||
}
|
||||
catch (err) {
|
||||
console.log(err)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// 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']
|
||||
|
||||
/*
|
||||
* 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)
|
||||
})
|
||||
}
|
||||
|
||||
/*
|
||||
* 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)
|
||||
})
|
||||
}
|
||||
|
||||
/*
|
||||
* Sample pattern for different models
|
||||
*/
|
||||
it('Sample pattern for different models:' , () => {
|
||||
expect(doesItSample(new Pattern({
|
||||
sample: {
|
||||
type: 'models',
|
||||
models: ourModels,
|
||||
},
|
||||
measurements
|
||||
}))).to.equal(true)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
module.exports = testPatternSampling
|
Loading…
Add table
Add a link
Reference in a new issue