Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pokemon-filter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AIT LAMINE Ilias
pokemon-filter
Commits
a6c9bea0
Commit
a6c9bea0
authored
2 months ago
by
Ait Lamine Ilias
Browse files
Options
Downloads
Patches
Plain Diff
test: test unitaire. Ref
#4
parent
255ec194
No related branches found
No related tags found
1 merge request
!9
test: test unitaire. Ref #4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
filtrage.js
+3
-24
3 additions, 24 deletions
filtrage.js
filtrage.test.js
+17
-4
17 additions, 4 deletions
filtrage.test.js
package.json
+1
-1
1 addition, 1 deletion
package.json
with
21 additions
and
29 deletions
filtrage.js
+
3
−
24
View file @
a6c9bea0
import
{
fetchPokemonList
}
from
'
./pokemonProvider.js
'
;
function
getPokemons
(
pokemons
)
{
const
list
=
pokemons
;
console
.
log
(
list
);
function
filterPokemons
(
pokemons
)
{
return
pokemons
.
filter
(
pokemon
=>
pokemon
.
weight
>
3
&&
pokemon
.
height
<
1
);
}
/**
* Filter Pokémon with weight > 3kg and height < 1m
*/
function
filterPokemons
()
{
fetchPokemonList
((
pokemons
)
=>
{
const
filteredPokemons
=
pokemons
.
filter
(
pokemon
=>
pokemon
.
weight
>
3
);
displayPokemons
(
filteredPokemons
);
},
318
);
// Fetch 318 Pokémon
}
function
filterPokemons2
()
{
fetchPokemonList
((
pokemons
)
=>
{
const
filteredPokemons
=
pokemons
.
filter
(
pokemon
=>
pokemon
.
height
<
1
);
displayPokemons
(
filteredPokemons
);
},
318
);
// Fetch 318 Pokémon
}
fetchPokemonList
(
getPokemons
,
20
);
\ No newline at end of file
module
.
exports
=
filterPokemons
;
\ No newline at end of file
This diff is collapsed.
Click to expand it.
filtrage.test.js
+
17
−
4
View file @
a6c9bea0
const
convert
=
require
(
'
./convert
'
);
// filterPokemons.test.js
const
filterPokemons
=
require
(
'
./filtrage
'
);
// Import your filter function
test
(
'
Conversion Euros to Dollars
'
,
()
=>
{
expect
(
convert
.
convertEurToUsd
(
3
)).
toBe
(
3.114
);
});
test
(
'
filters Pokémon with weight > 3kg and height < 1m
'
,
()
=>
{
const
pokemons
=
[
{
name
:
'
Pikachu
'
,
weight
:
6
,
height
:
0.4
},
{
name
:
'
Bulbasaur
'
,
weight
:
3
,
height
:
0.7
},
{
name
:
'
Squirtle
'
,
weight
:
4
,
height
:
0.9
},
{
name
:
'
Charizard
'
,
weight
:
10
,
height
:
1.7
}
];
const
filteredPokemons
=
filterPokemons
(
pokemons
);
// Assert that the filtered list contains only the valid Pokémon
expect
(
filteredPokemons
).
toEqual
([
{
name
:
'
Pikachu
'
,
weight
:
6
,
height
:
0.4
},
{
name
:
'
Squirtle
'
,
weight
:
4
,
height
:
0.9
}
]);
});
\ No newline at end of file
This diff is collapsed.
Click to expand it.
package.json
+
1
−
1
View file @
a6c9bea0
...
...
@@ -5,7 +5,7 @@
"main"
:
"pokemonProvider.js"
,
"type"
:
"module"
,
"scripts"
:
{
"test"
:
"
echo
\"
Error: no test specified
\"
&& exit 1
"
"test"
:
"
jest
"
},
"keywords"
:
[],
"author"
:
""
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment