-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix that EffectiveModuleSpecification.simplify() did not remove
redundant clauses
- Loading branch information
Showing
2 changed files
with
99 additions
and
10 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
spec/model/implementation/effective-module-specification.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { | ||
EffectiveModuleSpecification, | ||
EffectiveModuleSpecificationClause, | ||
} from '../../../src/model/implementation/modules/effective-module-specification'; | ||
import { expect } from 'chai'; | ||
|
||
describe('EffectiveModuleSpecification', () => { | ||
describe('simplify()', () => { | ||
it('removes duplicate simple clauses', () => { | ||
const input = new EffectiveModuleSpecification({ | ||
orCombinedClauses: [ | ||
new EffectiveModuleSpecificationClause({ andCombinedModules: ['a'] }), | ||
new EffectiveModuleSpecificationClause({ andCombinedModules: ['b'] }), | ||
new EffectiveModuleSpecificationClause({ andCombinedModules: ['a'] }), | ||
], | ||
}); | ||
const output = input.simplify(); | ||
expect(output.toString()).to.equal('a, b'); | ||
}); | ||
|
||
it('removes duplicate multi-module clauses', () => { | ||
const input = new EffectiveModuleSpecification({ | ||
orCombinedClauses: [ | ||
new EffectiveModuleSpecificationClause({ andCombinedModules: ['a', 'c'] }), | ||
new EffectiveModuleSpecificationClause({ andCombinedModules: ['b'] }), | ||
new EffectiveModuleSpecificationClause({ andCombinedModules: ['a', 'c'] }), | ||
], | ||
}); | ||
const output = input.simplify(); | ||
expect(output.toString()).to.equal('b, a && c'); | ||
}); | ||
|
||
it('removes redundant clauses', () => { | ||
const input = new EffectiveModuleSpecification({ | ||
orCombinedClauses: [ | ||
new EffectiveModuleSpecificationClause({ andCombinedModules: ['a', 'c'] }), | ||
new EffectiveModuleSpecificationClause({ andCombinedModules: ['b'] }), | ||
new EffectiveModuleSpecificationClause({ andCombinedModules: ['a', 'c', 'd'] }), | ||
], | ||
}); | ||
const output = input.simplify(); | ||
expect(output.toString()).to.equal('b, a && c'); | ||
}); | ||
|
||
it('works with a more complicated case', () => { | ||
const input = new EffectiveModuleSpecification({ | ||
orCombinedClauses: [ | ||
new EffectiveModuleSpecificationClause({ andCombinedModules: ['shipping'] }), | ||
new EffectiveModuleSpecificationClause({ | ||
andCombinedModules: ['shipping', 'dangerous_goods'], | ||
}), | ||
new EffectiveModuleSpecificationClause({ | ||
andCombinedModules: ['tms', 'dangerous_goods'], | ||
}), | ||
new EffectiveModuleSpecificationClause({ | ||
andCombinedModules: ['shipping', 'dangerous_goods', 'extra1'], | ||
}), | ||
new EffectiveModuleSpecificationClause({ | ||
andCombinedModules: ['tms', 'dangerous_goods', 'extra1'], | ||
}), | ||
new EffectiveModuleSpecificationClause({ | ||
andCombinedModules: ['extra1'], | ||
}), | ||
], | ||
}); | ||
const output = input.simplify(); | ||
expect(output.toString()).to.equal('extra1, shipping, dangerous_goods && tms'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters