|
| 1 | +import test from 'ava' |
| 2 | + |
| 3 | +import Specification, { AndSpecification, AndNotSpecification, OrSpecification, OrNotSpecification, NotSpecification } from '../specification' |
| 4 | + |
| 5 | +class IsOneSpecification extends Specification { |
| 6 | + public IsSatisfiedBy (candidate) { |
| 7 | + return candidate === 1 |
| 8 | + } |
| 9 | +} |
| 10 | + |
| 11 | +class IsTwoSpecification extends Specification { |
| 12 | + public IsSatisfiedBy (candidate) { |
| 13 | + return candidate === 2 |
| 14 | + } |
| 15 | +} |
| 16 | + |
| 17 | +const IsOne = new IsOneSpecification() |
| 18 | +const IsTwo = new IsTwoSpecification() |
| 19 | + |
| 20 | +// -- IsSatisfiedBy |
| 21 | +test('IsSatisfiedBy', t => { |
| 22 | + t.is(IsOne.IsSatisfiedBy(1), true) |
| 23 | +}) |
| 24 | + |
| 25 | +// -- And |
| 26 | +test('AndSpecification', t => { |
| 27 | + const And = new AndSpecification(IsOne, IsOne) |
| 28 | + t.is(And.IsSatisfiedBy(1), true) |
| 29 | +}) |
| 30 | + |
| 31 | +test('AndSpecification', t => { |
| 32 | + const And = new AndSpecification(IsOne, IsTwo) |
| 33 | + t.is(And.IsSatisfiedBy(1), false) |
| 34 | +}) |
| 35 | + |
| 36 | +test('AndNotSpecification', t => { |
| 37 | + const AndNot = new AndNotSpecification(IsOne, IsOne) |
| 38 | + t.is(AndNot.IsSatisfiedBy(1), false) |
| 39 | +}) |
| 40 | + |
| 41 | +// -- Or |
| 42 | +test('OrSpecification', t => { |
| 43 | + const Or = new OrSpecification(IsOne, IsTwo) |
| 44 | + t.is(Or.IsSatisfiedBy(1), true) |
| 45 | +}) |
| 46 | + |
| 47 | +test('OrSpecification', t => { |
| 48 | + const Or = new OrSpecification(IsOne, IsTwo) |
| 49 | + t.is(Or.IsSatisfiedBy(2), true) |
| 50 | +}) |
| 51 | + |
| 52 | +test('OrSpecification', t => { |
| 53 | + const Or = new OrSpecification(IsOne, IsTwo) |
| 54 | + t.is(Or.IsSatisfiedBy(3), false) |
| 55 | +}) |
| 56 | + |
| 57 | +// -- OrNot |
| 58 | +test('OrNotSpecification', t => { |
| 59 | + const OrNot = new OrNotSpecification(IsOne, IsTwo) |
| 60 | + t.is(OrNot.IsSatisfiedBy(1), true) |
| 61 | +}) |
| 62 | + |
| 63 | +test('OrNotSpecification', t => { |
| 64 | + const OrNot = new OrNotSpecification(IsOne, IsTwo) |
| 65 | + t.is(OrNot.IsSatisfiedBy(2), false) |
| 66 | +}) |
| 67 | + |
| 68 | +// -- Not |
| 69 | +test('NotSpecification', t => { |
| 70 | + const Not = new NotSpecification(IsOne) |
| 71 | + t.is(Not.IsSatisfiedBy(2), true) |
| 72 | +}) |
0 commit comments