Skip to content

Commit 088b220

Browse files
committed
added new tests
1 parent 4d3c115 commit 088b220

1 file changed

Lines changed: 37 additions & 5 deletions

File tree

Sprint-2/implement/lookup.test.js

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,46 @@ const createLookup = require("./lookup.js");
33
test("creates a country currency code lookup for multiple codes", () => {
44
const input = [
55
['US', 'USD'],
6-
['CA', 'CAD']
6+
['CA', 'CAD'],
7+
['UK', 'GBP'],
78
];
89
const expected = {
910
US: 'USD',
10-
CA: 'CAD'
11+
CA: 'CAD',
12+
UK: 'GBP'
1113
};
1214
expect(createLookup(input)).toEqual(expected);
1315
});
1416

17+
test("returns an empty object when given an empty array", () => {
18+
expect(createLookup([])).toEqual({});
19+
});
20+
21+
test("overwrites value if a country code appears more than once", () => {
22+
const input = [
23+
['UK', 'GBP'],
24+
['UK', 'POUND']
25+
];
26+
expect(createLookup(input)).toEqual({ UK: 'POUND' });
27+
});
28+
29+
test("ignores extra values in pairs", () => {
30+
const input = [
31+
['UK', 'GBP', 'Extra'],
32+
['US', 'USD']
33+
];
34+
expect(createLookup(input)).toEqual({ UK: 'GBP', US: 'USD' });
35+
});
36+
37+
test("ignores invalid pairs (less than two elements)", () => {
38+
const input = [
39+
['UK'], // Invalid
40+
['US', 'USD']
41+
];
42+
expect(createLookup(input)).toEqual({ US: 'USD' });
43+
});
44+
45+
1546
/*
1647
1748
Create a lookup object of key value pairs from an array of code pairs
@@ -20,7 +51,7 @@ Acceptance Criteria:
2051
2152
Given
2253
- An array of arrays representing country code and currency code pairs
23-
e.g. [['US', 'USD'], ['CA', 'CAD']]
54+
e.g. [['US', 'USD'], ['CA', 'CAD'],['UK','GBP']]
2455
2556
When
2657
- createLookup function is called with the country-currency array as an argument
@@ -31,7 +62,7 @@ Then
3162
- The values are the corresponding currency codes
3263
3364
Example
34-
Given: [['US', 'USD'], ['CA', 'CAD']]
65+
Given: [['US', 'USD'], ['CA', 'CAD'], ['UK', 'GPB']]
3566
3667
When
3768
createLookup(countryCurrencyPairs) is called
@@ -40,6 +71,7 @@ Then
4071
It should return:
4172
{
4273
'US': 'USD',
43-
'CA': 'CAD'
74+
'CA': 'CAD',
75+
'UK': 'GBP'
4476
}
4577
*/

0 commit comments

Comments
 (0)