diff --git a/exercises/concept/annalyns-infiltration/annalyns-infiltration.spec.js b/exercises/concept/annalyns-infiltration/annalyns-infiltration.spec.js index 4f870deca7..abec916d66 100644 --- a/exercises/concept/annalyns-infiltration/annalyns-infiltration.spec.js +++ b/exercises/concept/annalyns-infiltration/annalyns-infiltration.spec.js @@ -23,85 +23,389 @@ describe("Annalyn's infiltration", () => { }); describe('can spy', () => { - const CHARACTERS_STATE_COMBINATIONS = [ - [false, false, false, false], - [false, false, true, true], - [false, true, false, true], - [false, true, true, true], - [true, false, false, true], - [true, false, true, true], - [true, true, true, true], - ]; - - CHARACTERS_STATE_COMBINATIONS.forEach( - ([knightIsAwake, archerIsAwake, prisonerIsAwake, expected]) => { - test(`canSpy(${knightIsAwake}, ${archerIsAwake}, ${prisonerIsAwake})`, () => { - expect(canSpy(knightIsAwake, archerIsAwake, prisonerIsAwake)).toBe( - expected - ); - }); - } - ); + test('when everyone is asleep', () => { + const knightIsAwake = false; + const archerIsAwake = false; + const prisonerIsAwake = false; + const expected = false; + + expect(canSpy(knightIsAwake, archerIsAwake, prisonerIsAwake)).toBe( + expected + ); + }); + + test('when only the prisoner is awake', () => { + const knightIsAwake = false; + const archerIsAwake = false; + const prisonerIsAwake = true; + const expected = true; + + expect(canSpy(knightIsAwake, archerIsAwake, prisonerIsAwake)).toBe( + expected + ); + }); + + test('when only the archer is awake', () => { + const knightIsAwake = false; + const archerIsAwake = true; + const prisonerIsAwake = false; + const expected = true; + + expect(canSpy(knightIsAwake, archerIsAwake, prisonerIsAwake)).toBe( + expected + ); + }); + + test('when only the knight is asleep', () => { + const knightIsAwake = false; + const archerIsAwake = true; + const prisonerIsAwake = true; + const expected = true; + + expect(canSpy(knightIsAwake, archerIsAwake, prisonerIsAwake)).toBe( + expected + ); + }); + + test('when only the knight is awake', () => { + const knightIsAwake = true; + const archerIsAwake = false; + const prisonerIsAwake = false; + const expected = true; + + expect(canSpy(knightIsAwake, archerIsAwake, prisonerIsAwake)).toBe( + expected + ); + }); + + test('when only the archer is asleep', () => { + const knightIsAwake = true; + const archerIsAwake = false; + const prisonerIsAwake = true; + const expected = true; + + expect(canSpy(knightIsAwake, archerIsAwake, prisonerIsAwake)).toBe( + expected + ); + }); + + test('when everyone is awake', () => { + const knightIsAwake = true; + const archerIsAwake = true; + const prisonerIsAwake = true; + const expected = true; + + expect(canSpy(knightIsAwake, archerIsAwake, prisonerIsAwake)).toBe( + expected + ); + }); }); describe('can signal prisoner', () => { - const CHARACTERS_STATE_COMBINATIONS = [ - [false, false, false], - [false, true, true], - [true, false, false], - [true, true, false], - ]; - - CHARACTERS_STATE_COMBINATIONS.forEach( - ([archerIsAwake, prisonerIsAwake, expected]) => { - test(`canSignalPrisoner(${archerIsAwake}, ${prisonerIsAwake})`, () => { - expect(canSignalPrisoner(archerIsAwake, prisonerIsAwake)).toBe( - expected - ); - }); - } - ); + test('when everyone is asleep', () => { + const archerIsAwake = false; + const prisonerIsAwake = false; + const expected = false; + + expect(canSignalPrisoner(archerIsAwake, prisonerIsAwake)).toBe(expected); + }); + + test('when only the prisoner is awake', () => { + const archerIsAwake = false; + const prisonerIsAwake = true; + const expected = true; + + expect(canSignalPrisoner(archerIsAwake, prisonerIsAwake)).toBe(expected); + }); + + test('when only the archer is awake', () => { + const archerIsAwake = true; + const prisonerIsAwake = false; + const expected = false; + + expect(canSignalPrisoner(archerIsAwake, prisonerIsAwake)).toBe(expected); + }); + + test('when everyone is awake', () => { + const archerIsAwake = true; + const prisonerIsAwake = true; + const expected = false; + + expect(canSignalPrisoner(archerIsAwake, prisonerIsAwake)).toBe(expected); + }); }); describe('can free prisoner', () => { - const CHARACTERS_STATE_COMBINATIONS = [ - [false, false, false, false, false], - [false, false, false, true, true], - [false, false, true, false, true], - [false, false, true, true, true], - [false, true, false, false, false], - [false, true, false, true, false], - [false, true, true, false, false], - [false, true, true, true, false], - [true, false, false, false, false], - [true, false, false, true, true], - [true, false, true, false, false], - [true, false, true, true, true], - [true, true, false, false, false], - [true, true, false, true, false], - [true, true, true, false, false], - [true, true, true, true, false], - ]; - - CHARACTERS_STATE_COMBINATIONS.forEach( - ([ - knightIsAwake, - archerIsAwake, - prisonerIsAwake, - petDogIsPresent, - expected, - ]) => { - test(`canFreePrisoner(${knightIsAwake}, ${archerIsAwake}, ${prisonerIsAwake}, ${petDogIsPresent})`, () => { - expect( - canFreePrisoner( - knightIsAwake, - archerIsAwake, - prisonerIsAwake, - petDogIsPresent - ) - ).toBe(expected); - }); - } - ); + test('when everyone is asleep and pet dog is not present', () => { + const knightIsAwake = false; + const archerIsAwake = false; + const prisonerIsAwake = false; + const petDogIsPresent = false; + const expected = false; + + expect( + canFreePrisoner( + knightIsAwake, + archerIsAwake, + prisonerIsAwake, + petDogIsPresent + ) + ).toBe(expected); + }); + + test('when everyone is asleep and pet dog is present', () => { + const knightIsAwake = false; + const archerIsAwake = false; + const prisonerIsAwake = false; + const petDogIsPresent = true; + const expected = true; + + expect( + canFreePrisoner( + knightIsAwake, + archerIsAwake, + prisonerIsAwake, + petDogIsPresent + ) + ).toBe(expected); + }); + + test('when only the prisoner is awake and pet dog is not present', () => { + const knightIsAwake = false; + const archerIsAwake = false; + const prisonerIsAwake = true; + const petDogIsPresent = false; + const expected = true; + + expect( + canFreePrisoner( + knightIsAwake, + archerIsAwake, + prisonerIsAwake, + petDogIsPresent + ) + ).toBe(expected); + }); + + test('when only the prisoner is awake and pet dog is present', () => { + const knightIsAwake = false; + const archerIsAwake = false; + const prisonerIsAwake = true; + const petDogIsPresent = true; + const expected = true; + + expect( + canFreePrisoner( + knightIsAwake, + archerIsAwake, + prisonerIsAwake, + petDogIsPresent + ) + ).toBe(expected); + }); + + test('when only the archer is awake and pet dog is not present', () => { + const knightIsAwake = false; + const archerIsAwake = true; + const prisonerIsAwake = false; + const petDogIsPresent = false; + const expected = false; + + expect( + canFreePrisoner( + knightIsAwake, + archerIsAwake, + prisonerIsAwake, + petDogIsPresent + ) + ).toBe(expected); + }); + + test('when only the archer is awake and pet dog is present', () => { + const knightIsAwake = false; + const archerIsAwake = true; + const prisonerIsAwake = false; + const petDogIsPresent = true; + const expected = false; + + expect( + canFreePrisoner( + knightIsAwake, + archerIsAwake, + prisonerIsAwake, + petDogIsPresent + ) + ).toBe(expected); + }); + + test('when only the knight is asleep and pet dog is not present', () => { + const knightIsAwake = false; + const archerIsAwake = true; + const prisonerIsAwake = true; + const petDogIsPresent = false; + const expected = false; + + expect( + canFreePrisoner( + knightIsAwake, + archerIsAwake, + prisonerIsAwake, + petDogIsPresent + ) + ).toBe(expected); + }); + + test('when only the knight is asleep and pet dog is present', () => { + const knightIsAwake = false; + const archerIsAwake = true; + const prisonerIsAwake = true; + const petDogIsPresent = true; + const expected = false; + + expect( + canFreePrisoner( + knightIsAwake, + archerIsAwake, + prisonerIsAwake, + petDogIsPresent + ) + ).toBe(expected); + }); + + test('when only the knight is awake and pet dog is not present', () => { + const knightIsAwake = true; + const archerIsAwake = false; + const prisonerIsAwake = false; + const petDogIsPresent = false; + const expected = false; + + expect( + canFreePrisoner( + knightIsAwake, + archerIsAwake, + prisonerIsAwake, + petDogIsPresent + ) + ).toBe(expected); + }); + + test('when only the knight is awake and pet dog is present', () => { + const knightIsAwake = true; + const archerIsAwake = false; + const prisonerIsAwake = false; + const petDogIsPresent = true; + const expected = true; + + expect( + canFreePrisoner( + knightIsAwake, + archerIsAwake, + prisonerIsAwake, + petDogIsPresent + ) + ).toBe(expected); + }); + + test('when only the archer is asleep and pet dog is not present', () => { + const knightIsAwake = true; + const archerIsAwake = false; + const prisonerIsAwake = true; + const petDogIsPresent = false; + const expected = false; + + expect( + canFreePrisoner( + knightIsAwake, + archerIsAwake, + prisonerIsAwake, + petDogIsPresent + ) + ).toBe(expected); + }); + + test('when only the archer is asleep and pet dog is present', () => { + const knightIsAwake = true; + const archerIsAwake = false; + const prisonerIsAwake = true; + const petDogIsPresent = true; + const expected = true; + + expect( + canFreePrisoner( + knightIsAwake, + archerIsAwake, + prisonerIsAwake, + petDogIsPresent + ) + ).toBe(expected); + }); + + test('when only the prisoner is asleep and pet dog is not present', () => { + const knightIsAwake = true; + const archerIsAwake = true; + const prisonerIsAwake = false; + const petDogIsPresent = false; + const expected = false; + + expect( + canFreePrisoner( + knightIsAwake, + archerIsAwake, + prisonerIsAwake, + petDogIsPresent + ) + ).toBe(expected); + }); + + test('when only the prisoner is asleep and pet dog is present', () => { + const knightIsAwake = true; + const archerIsAwake = true; + const prisonerIsAwake = false; + const petDogIsPresent = true; + const expected = false; + + expect( + canFreePrisoner( + knightIsAwake, + archerIsAwake, + prisonerIsAwake, + petDogIsPresent + ) + ).toBe(expected); + }); + + test('when everyone is awake and pet dog is not present', () => { + const knightIsAwake = true; + const archerIsAwake = true; + const prisonerIsAwake = true; + const petDogIsPresent = false; + const expected = false; + + expect( + canFreePrisoner( + knightIsAwake, + archerIsAwake, + prisonerIsAwake, + petDogIsPresent + ) + ).toBe(expected); + }); + + test('when everyone is awake and pet dog is present', () => { + const knightIsAwake = true; + const archerIsAwake = true; + const prisonerIsAwake = true; + const petDogIsPresent = true; + const expected = false; + + expect( + canFreePrisoner( + knightIsAwake, + archerIsAwake, + prisonerIsAwake, + petDogIsPresent + ) + ).toBe(expected); + }); }); });