Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
td-git
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
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
CORONA Nikola
td-git
Commits
b68fbb6f
Commit
b68fbb6f
authored
1 month ago
by
CORONA Nikola
Browse files
Options
Downloads
Patches
Plain Diff
TD5 Exercice 4
parent
1293ae91
Loading
Loading
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
TD5 Test/Exercice.test.ts
+35
-6
35 additions, 6 deletions
TD5 Test/Exercice.test.ts
TD5 Test/MesMaths.ts
+38
-19
38 additions, 19 deletions
TD5 Test/MesMaths.ts
with
73 additions
and
25 deletions
TD5 Test/Exercice.test.ts
+
35
−
6
View file @
b68fbb6f
import
{
multAdd
,
puissanceMult
}
from
"
./MesMaths.ts
"
;
import
{
multAdd
,
puissanceMult
,
creeInitiales
,
ErreurPuissanceMult
}
from
"
./MesMaths.ts
"
;
import
{
assertEquals
}
from
"
jsr:@std/assert/equals
"
;
import
{
assertThrows
}
from
"
jsr:@std/assert/throws
"
;
import
{
assertAlmostEquals
}
from
"
jsr:@std/assert/almost-equals
"
;
// Exercice 1
Deno
.
test
(
"
cas général
"
,
()
=>
{
assertEquals
(
multAdd
(
3
,
8
),
24
);
});
...
...
@@ -14,11 +17,37 @@ Deno.test("multiplication par un nombre négatif", () => {
Deno
.
test
(
"
multiplication par 2 nombre négatif
"
,
()
=>
{
assertEquals
(
multAdd
(
-
8
,
-
8
),
64
);
});
Deno
.
test
(
"
Puissance par un nombre négatif
"
,
()
=>
{
assertEquals
(
puissanceMult
(
-
5
,
9
),
-
1953125
);
});
Deno
.
test
(
"
Puissance par un nombre négatif
"
,
()
=>
{
assertEquals
(
puissanceMult
(
5
,
-
9
),
-
1953125
);
//Exercice 2
Deno
.
test
(
"
puissanceMult cas normaux
"
,
()
=>
{
assertEquals
(
puissanceMult
(
2
,
3
),
8
);
assertEquals
(
puissanceMult
(
5
,
0
),
1
);
assertEquals
(
puissanceMult
(
0
,
5
),
0
);
assertEquals
(
puissanceMult
(
-
2
,
3
),
-
8
);
assertEquals
(
puissanceMult
(
3
,
1
),
3
);
});
Deno
.
test
(
"
puissanceMult erreur exposant négatif
"
,
()
=>
{
assertThrows
(
()
=>
puissanceMult
(
3
,
-
2
),
ErreurPuissanceMult
,
"
L'exposant ne peut pas être négatif.
"
);
});
Deno
.
test
(
"
puissanceMult erreur exposant non entier
"
,
()
=>
{
assertThrows
(
()
=>
puissanceMult
(
2
,
3.14
),
ErreurPuissanceMult
,
"
Le second paramètre doit être un entier.
"
);
});
// Exercice 3
Deno
.
test
(
"
Teste de la fonction creeInitiales avec Nikola Corona
"
,
()
=>
{
assertEquals
(
creeInitiales
(
"
corona
"
,
"
nikola
"
),
"
CN
"
)
});
...
...
This diff is collapsed.
Click to expand it.
TD5 Test/MesMaths.ts
+
38
−
19
View file @
b68fbb6f
// Exercice 1
export
function
multAdd
(
x
:
number
,
y
:
number
):
number
{
let
resultat
=
0
;
let
inf
=
0
;
if
(
y
<
0
){
y
=
-
y
inf
=
1
;
if
(
y
<
0
)
{
y
=
-
y
;
inf
=
1
;
}
for
(
let
i
=
0
;
i
<
y
;
i
++
)
{
resultat
+=
x
;
resultat
+=
x
;
}
if
(
inf
===
1
)
return
-
resultat
;
if
(
inf
===
1
)
return
-
resultat
;
else
return
resultat
;
}
}
export
function
puissanceMult
(
x
:
number
,
y
:
number
):
number
{
let
val
=
1
;
let
inf
=
0
;
if
(
y
<
0
){
y
=
-
y
inf
=
1
;
// Exercice 2
export
function
puissanceMult
(
x
:
number
,
y
:
number
):
number
{
if
(
!
Number
.
isInteger
(
y
))
{
throw
new
ErreurPuissanceMult
(
"
Le second paramètre doit être un entier.
"
);
}
if
(
y
<
0
)
{
throw
new
ErreurPuissanceMult
(
"
L'exposant ne peut pas être négatif.
"
);
}
let
val
=
1
;
for
(
let
i
=
0
;
i
<
y
;
i
++
)
{
val
*=
x
;
val
*=
x
;
}
if
(
inf
===
1
)
return
-
val
;
else
return
val
;
return
val
;
}
}
export
class
ErreurPuissanceMult
extends
Error
{
constructor
(
msg
:
string
)
{
super
(
msg
);
this
.
name
=
"
ErreurPuissanceMult
"
;
}
}
// 1) on doit tester pour y negatif car il renvoit 1
// 1) on doit tester pour y negatif car il renvoit 1
const
x
=
2.1
;
const
y
=
3.14
;
console
.
log
(
"
Number.isInteger(x) =
"
,
Number
.
isInteger
(
x
));
console
.
log
(
"
Number.isInteger(y) =
"
,
Number
.
isInteger
(
y
));
\ No newline at end of file
console
.
log
(
"
Number.isInteger(y) =
"
,
Number
.
isInteger
(
y
));
// Exercice 3
export
function
creeInitiales
(
nom
:
string
,
prenom
:
string
):
string
{
return
nom
[
0
].
toUpperCase
()
+
prenom
[
0
].
toUpperCase
();
}
console
.
log
(
creeInitiales
(
"
corona
"
,
"
nikola
"
))
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