|
| 1 | +import { speeds, airSpeedVelocity, plumage, plumages } from './index'; |
| 2 | + |
| 3 | +describe('plumage', () => { |
| 4 | + it('should return "average" for EuropeanSwallow', () => { |
| 5 | + const bird = { type: 'EuropeanSwallow' }; |
| 6 | + expect(plumage(bird)).toBe('average'); |
| 7 | + }); |
| 8 | + |
| 9 | + it('should return "tired" for AfricanSwallow with more than 2 coconuts', () => { |
| 10 | + const bird = { type: 'AfricanSwallow', numberOfCoconuts: 3 }; |
| 11 | + expect(plumage(bird)).toBe('tired'); |
| 12 | + }); |
| 13 | + |
| 14 | + it('should return "average" for AfricanSwallow with 2 or less coconuts', () => { |
| 15 | + const bird = { type: 'AfricanSwallow', numberOfCoconuts: 2 }; |
| 16 | + expect(plumage(bird)).toBe('average'); |
| 17 | + }); |
| 18 | + |
| 19 | + it('should return "scorched" for NorwegianBlueParrot with voltage greater than 100', () => { |
| 20 | + const bird = { type: 'NorwegianBlueParrot', voltage: 101 }; |
| 21 | + expect(plumage(bird)).toBe('scorched'); |
| 22 | + }); |
| 23 | + |
| 24 | + it('should return "beautiful" for NorwegianBlueParrot with voltage 100 or less', () => { |
| 25 | + const bird = { type: 'NorwegianBlueParrot', voltage: 100 }; |
| 26 | + expect(plumage(bird)).toBe('beautiful'); |
| 27 | + }); |
| 28 | + |
| 29 | + it('should return "unknown" for unknown bird type', () => { |
| 30 | + const bird = { type: 'Unknown' }; |
| 31 | + expect(plumage(bird)).toBe('unknown'); |
| 32 | + }); |
| 33 | +}); |
| 34 | + |
| 35 | +describe('plumages', () => { |
| 36 | + it('should return a map containing the plumage of all birds in the list', () => { |
| 37 | + const birds = [ |
| 38 | + { name: 'bird1', type: 'EuropeanSwallow' }, |
| 39 | + { name: 'bird2', type: 'AfricanSwallow', numberOfCoconuts: 1 }, |
| 40 | + { name: 'bird3', type: 'AfricanSwallow', numberOfCoconuts: 3 }, |
| 41 | + { name: 'bird4', type: 'NorwegianBlueParrot', voltage: 100 }, |
| 42 | + { name: 'bird5', type: 'NorwegianBlueParrot', voltage: 101 }, |
| 43 | + { name: 'bird6', type: 'Unknown' }, |
| 44 | + ]; |
| 45 | + |
| 46 | + const result = plumages(birds); |
| 47 | + |
| 48 | + expect(result.size).toBe(6); |
| 49 | + expect(result.get('bird1')).toBe(plumage(birds[0])); |
| 50 | + expect(result.get('bird2')).toBe(plumage(birds[1])); |
| 51 | + expect(result.get('bird3')).toBe(plumage(birds[2])); |
| 52 | + expect(result.get('bird4')).toBe(plumage(birds[3])); |
| 53 | + expect(result.get('bird5')).toBe(plumage(birds[4])); |
| 54 | + expect(result.get('bird6')).toBe(plumage(birds[5])); |
| 55 | + }); |
| 56 | +}); |
| 57 | + |
| 58 | +describe('airSpeedVelocity', () => { |
| 59 | + it('should return 35 for EuropeanSwallow', () => { |
| 60 | + const bird = { type: 'EuropeanSwallow' }; |
| 61 | + expect(airSpeedVelocity(bird)).toBe(35); |
| 62 | + }); |
| 63 | + |
| 64 | + it('should return 38 for AfricanSwallow with 1 coconut', () => { |
| 65 | + const bird = { type: 'AfricanSwallow', numberOfCoconuts: 1 }; |
| 66 | + expect(airSpeedVelocity(bird)).toBe(38); |
| 67 | + }); |
| 68 | + |
| 69 | + it('should return 36 for AfricanSwallow with 2 coconuts', () => { |
| 70 | + const bird = { type: 'AfricanSwallow', numberOfCoconuts: 2 }; |
| 71 | + expect(airSpeedVelocity(bird)).toBe(36); |
| 72 | + }); |
| 73 | + |
| 74 | + it('should return 0 for nailed NorwegianBlueParrot', () => { |
| 75 | + const bird = { type: 'NorwegianBlueParrot', isNailed: true }; |
| 76 | + expect(airSpeedVelocity(bird)).toBe(0); |
| 77 | + }); |
| 78 | + |
| 79 | + it('should return 10 for NorwegianBlueParrot with voltage 0', () => { |
| 80 | + const bird = { type: 'NorwegianBlueParrot', voltage: 0 }; |
| 81 | + expect(airSpeedVelocity(bird)).toBe(10); |
| 82 | + }); |
| 83 | + |
| 84 | + it('should return 20 for NorwegianBlueParrot with voltage 100', () => { |
| 85 | + const bird = { type: 'NorwegianBlueParrot', voltage: 100 }; |
| 86 | + expect(airSpeedVelocity(bird)).toBe(20); |
| 87 | + }); |
| 88 | +}); |
| 89 | + |
| 90 | +describe('speeds', () => { |
| 91 | + it('should return a map containing the air speed velocity of all birds in the list', () => { |
| 92 | + const birds = [ |
| 93 | + { name: 'bird1', type: 'EuropeanSwallow' }, |
| 94 | + { name: 'bird2', type: 'AfricanSwallow', numberOfCoconuts: 1 }, |
| 95 | + { name: 'bird3', type: 'AfricanSwallow', numberOfCoconuts: 2 }, |
| 96 | + { name: 'bird4', type: 'NorwegianBlueParrot', voltage: 100 }, |
| 97 | + { name: 'bird5', type: 'NorwegianBlueParrot', voltage: 50 }, |
| 98 | + { name: 'bird6', type: 'Unknown' }, |
| 99 | + ]; |
| 100 | + |
| 101 | + const result = speeds(birds); |
| 102 | + |
| 103 | + expect(result.size).toBe(6); |
| 104 | + expect(result.get('bird1')).toBe(35); |
| 105 | + expect(result.get('bird2')).toBe(38); |
| 106 | + expect(result.get('bird3')).toBe(36); |
| 107 | + expect(result.get('bird4')).toBe(20); |
| 108 | + expect(result.get('bird5')).toBe(15); |
| 109 | + expect(result.get('bird6')).toBe(null); |
| 110 | + }); |
| 111 | +}); |
0 commit comments