diff --git a/4.student-exercises.js b/4.student-exercises.js new file mode 100644 index 0000000..bd6619f --- /dev/null +++ b/4.student-exercises.js @@ -0,0 +1,17 @@ +const getTrainersAndGymsAndPokemons = (gyms, trainers, pokemons) => { + // Your code here +}; + +const getPsychicTrainersAndGyms = (gyms, trainers, pokemons) => { + // Your code here +}; + +const getGymsWithPokemons = (gyms, trainers, pokemons, ...pokemonsToFind) => { + // Your code here +}; + +module.exports = { + getPsychicTrainersAndGyms, + getTrainersAndGymsAndPokemons, + getGymsWithPokemons +}; diff --git a/4.student-exercises.test.js b/4.student-exercises.test.js new file mode 100644 index 0000000..1d233b4 --- /dev/null +++ b/4.student-exercises.test.js @@ -0,0 +1,71 @@ +const pokemons = require("./pokeData"); +const trainers = require("./trainerData"); +const gyms = require("./gymData"); + +const { + getPsychicTrainersAndGyms, + getTrainersAndGymsAndPokemons, + getGymsWithPokemons +} = require("./4.student-exercises"); + +test("getTrainersAndGymsAndPokemons", () => { + const trainersAndGymsAndPokemons = getTrainersAndGymsAndPokemons( + gyms, + trainers, + pokemons + ); + expect(trainersAndGymsAndPokemons.length).toBe(9); + expect(trainersAndGymsAndPokemons.map(trainer => trainer.gym)).toEqual( + expect.any(Object) + ); + expect(trainersAndGymsAndPokemons.map(trainer => trainer.pokemons)).toEqual( + expect.any(Array) + ); +}); + +test(`getPsychicTrainersAndGyms: expect a list of trainers with psychic pokemons. + also include (all) their pokemons and their gym`, () => { + const result = getPsychicTrainersAndGyms(gyms, trainers, pokemons); + expect(result.length).toEqual(2); + expect(result[0].name).toBe("Sabrina"); + expect(result[1].name).toBe("Misty"); + expect(result[0].gym).toEqual(expect.any(Object)); + expect(result[1].gym).toEqual(expect.any(Object)); + expect(result[0].gym.city).toBe("Saffron City"); + expect(result[1].gym.city).toBe("Cerulean City"); + expect(result[0].pokemons).toEqual(expect.any(Array)); + expect(result[1].pokemons).toEqual(expect.any(Array)); + expect(result[0].pokemons.length).toBe(4); + expect(result[1].pokemons.length).toBe(2); +}); + +test("getGymsWithPokemons: expect a list of gyms where certain pokemons can be found", () => { + const result = getGymsWithPokemons( + gyms, + trainers, + pokemons, + "Gloom", + "Starmie" + ); + result.forEach(pokemon => { + expect(pokemon).toEqual( + expect.objectContaining({ + id: expect.any(Number), + name: expect.any(String), + trainers: expect.any(Array), + gyms: expect.any(Array) + }) + ); + }); + expect(result.length).toEqual(2); + expect(result[0].trainers.length).toEqual(2); + expect(result[1].trainers.length).toEqual(1); + expect(result[0].trainers[0].name).toBe("Brock"); + expect(result[0].trainers[1].name).toBe("Erika"); + expect(result[1].trainers[0].name).toBe("Misty"); + expect(result[0].gyms.length).toEqual(2); + expect(result[1].gyms.length).toEqual(1); + expect(result[0].gyms[0].city).toBe("Celadon City"); + expect(result[0].gyms[1].city).toBe("Pewter City"); + expect(result[1].gyms[0].city).toBe("Cerulean City"); +}); diff --git a/gymData.js b/gymData.js index 2bda417..887fdf7 100644 --- a/gymData.js +++ b/gymData.js @@ -1,10 +1,10 @@ module.exports = [ - { id: 1, city: 'Saffron City', trainerId: 2 }, - { id: 2, city: 'Fuchsia City', trainerId: 3 }, - { id: 3, city: 'Cinnabar Island', trainerId: 5 }, - { id: 4, city: 'Celadon City ', trainerId: 7 }, - { id: 5, city: 'Cerulean City', trainerId: 8 }, - { id: 6, city: 'Vermilion City', trainerId: 6 }, - { id: 7, city: 'Pewter City', trainerId: 1 }, - { id: 8, city: 'Viridian City', trainerId: 4 }, -] \ No newline at end of file + { id: 1, city: "Saffron City", trainerId: 2 }, + { id: 2, city: "Fuchsia City", trainerId: 3 }, + { id: 3, city: "Cinnabar Island", trainerId: 5 }, + { id: 4, city: "Celadon City", trainerId: 7 }, + { id: 5, city: "Cerulean City", trainerId: 8 }, + { id: 6, city: "Vermilion City", trainerId: 6 }, + { id: 7, city: "Pewter City", trainerId: 1 }, + { id: 8, city: "Viridian City", trainerId: 4 } +]; diff --git a/package.json b/package.json index 04a5cdc..5b5eb8f 100644 --- a/package.json +++ b/package.json @@ -1,17 +1,18 @@ { - "name": "data-transformations", - "version": "1.0.0", - "description": "A set of exercises for the data transformation day", - "main": "index.js", - "scripts": { - "test": "jest --watch", - "exercise1": "jest 1.map-filter-find.test --watch", - "exercise2": "jest 2.reduce.test --watch", - "exercise3": "jest 3.data-mining.test --watch" - }, - "author": "Codaisseur", - "license": "ISC", - "devDependencies": { - "jest": "^24.7.1" - } -} \ No newline at end of file + "name": "data-transformations", + "version": "1.0.0", + "description": "A set of exercises for the data transformation day", + "main": "index.js", + "scripts": { + "test": "jest --watch", + "exercise1": "jest 1.map-filter-find.test --watch", + "exercise2": "jest 2.reduce.test --watch", + "exercise3": "jest 3.data-mining.test --watch", + "exercise4": "jest 4.student-exercises.test --watch" + }, + "author": "Codaisseur", + "license": "ISC", + "devDependencies": { + "jest": "^24.7.1" + } +} diff --git a/trainerData.js b/trainerData.js index bf27fd2..152bb1d 100644 --- a/trainerData.js +++ b/trainerData.js @@ -1,11 +1,11 @@ module.exports = [ - { id: 1, name: 'Brock', pokemonIds: [74, 95] }, - { id: 2, name: 'Sabrina', pokemonIds: [64, 122, 49, 65] }, - { id: 3, name: 'Koga', pokemonIds: [109, 110, 109, 89] }, - { id: 4, name: 'Giovanni', pokemonIds: [112, 51, 31, 34, 113] }, - { id: 5, name: 'Blaine', pokemonIds: [58, 77, 78, 59] }, - { id: 6, name: 'Lt. Surge', pokemonIds: [100, 25, 26] }, - { id: 7, name: 'Erika', pokemonIds: [71, 114, 44] }, - { id: 8, name: 'Misty', pokemonIds: [120, 121] }, - { id: 9, name: 'Ash', pokemonIds: [25, 1, 7, 6, 17, 12] }, -] \ No newline at end of file + { id: 1, name: "Brock", pokemonIds: [74, 95, 44] }, + { id: 2, name: "Sabrina", pokemonIds: [64, 122, 49, 65] }, + { id: 3, name: "Koga", pokemonIds: [109, 110, 109, 89] }, + { id: 4, name: "Giovanni", pokemonIds: [112, 51, 31, 34, 113] }, + { id: 5, name: "Blaine", pokemonIds: [58, 77, 78, 59] }, + { id: 6, name: "Lt. Surge", pokemonIds: [100, 25, 26] }, + { id: 7, name: "Erika", pokemonIds: [71, 114, 44] }, + { id: 8, name: "Misty", pokemonIds: [120, 121] }, + { id: 9, name: "Ash", pokemonIds: [25, 1, 7, 6, 17, 12] } +];