Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
webcalc-rs
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
Michael Hauspie
webcalc-rs
Commits
6f2210b1
Commit
6f2210b1
authored
1 year ago
by
Michael Hauspie
Browse files
Options
Downloads
Patches
Plain Diff
Add Moins
parent
f74d8421
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main.rs
+20
-6
20 additions, 6 deletions
src/main.rs
src/operations.rs
+15
-1
15 additions, 1 deletion
src/operations.rs
with
35 additions
and
7 deletions
src/main.rs
+
20
−
6
View file @
6f2210b1
...
@@ -60,6 +60,13 @@ mod tests {
...
@@ -60,6 +60,13 @@ mod tests {
use
rocket
::
uri
;
use
rocket
::
uri
;
use
super
::
*
;
use
super
::
*
;
fn
build_response
<
'r
>
(
operation
:
Operation
)
->
(
Status
,
OperationResult
)
{
let
client
=
Client
::
tracked
(
launch
())
.expect
(
"valid rocket instance"
);
let
req
=
client
.post
(
uri!
(
super
::
index
))
.json
(
&
operation
);
let
response
=
req
.dispatch
();
(
response
.status
(),
response
.into_json
::
<
OperationResult
>
()
.unwrap
())
}
#[test]
#[test]
fn
index
()
{
fn
index
()
{
let
client
=
Client
::
tracked
(
launch
())
.expect
(
"valid rocket instance"
);
let
client
=
Client
::
tracked
(
launch
())
.expect
(
"valid rocket instance"
);
...
@@ -71,13 +78,20 @@ mod tests {
...
@@ -71,13 +78,20 @@ mod tests {
#[test]
#[test]
fn
plus
()
{
fn
plus
()
{
let
client
=
Client
::
tracked
(
launch
())
.expect
(
"valid rocket instance"
);
let
(
status
,
response
)
=
build_response
(
Operation
::
Plus
(
3
,
8
));
let
operation
=
Operation
::
Plus
(
3
,
8
);
assert_eq!
(
status
,
Status
::
Ok
);
let
req
=
client
.post
(
uri!
(
super
::
index
))
.json
(
&
operation
);
let
response
=
req
.dispatch
();
assert_eq!
(
response
.status
(),
Status
::
Ok
);
let
expected
=
OperationResult
::
new
(
"3 + 8"
,
11
);
let
expected
=
OperationResult
::
new
(
"3 + 8"
,
11
);
assert_eq!
(
response
.into_json
::
<
OperationResult
>
()
.unwrap
(),
expected
);
assert_eq!
(
response
,
expected
);
}
#[test]
fn
moins
()
{
let
(
status
,
response
)
=
build_response
(
Operation
::
Moins
(
10
,
20
));
assert_eq!
(
status
,
Status
::
Ok
);
let
expected
=
OperationResult
::
new
(
"10 - 20"
,
-
10
);
assert_eq!
(
response
,
expected
);
}
}
}
}
This diff is collapsed.
Click to expand it.
src/operations.rs
+
15
−
1
View file @
6f2210b1
...
@@ -7,6 +7,7 @@ use serde::{Deserialize, Serialize};
...
@@ -7,6 +7,7 @@ use serde::{Deserialize, Serialize};
#[derive(Serialize,
Deserialize,
Copy,
Clone,
Debug)]
#[derive(Serialize,
Deserialize,
Copy,
Clone,
Debug)]
pub
enum
Operation
{
pub
enum
Operation
{
Plus
(
i32
,
i32
),
Plus
(
i32
,
i32
),
Moins
(
i32
,
i32
),
}
}
#[derive(Deserialize,
Serialize,
PartialEq,
Debug)]
#[derive(Deserialize,
Serialize,
PartialEq,
Debug)]
...
@@ -31,7 +32,11 @@ impl From<&Operation> for OperationResult {
...
@@ -31,7 +32,11 @@ impl From<&Operation> for OperationResult {
Operation
::
Plus
(
op1
,
op2
)
=>
OperationResult
{
Operation
::
Plus
(
op1
,
op2
)
=>
OperationResult
{
operation
:
format!
(
"{op1} + {op2}"
),
operation
:
format!
(
"{op1} + {op2}"
),
resultat
:
op1
+
op2
,
resultat
:
op1
+
op2
,
}
},
Operation
::
Moins
(
op1
,
op2
)
=>
OperationResult
{
operation
:
format!
(
"{op1} - {op2}"
),
resultat
:
op1
-
op2
,
},
}
}
}
}
}
}
...
@@ -55,5 +60,14 @@ mod tests {
...
@@ -55,5 +60,14 @@ mod tests {
assert_eq!
(
result
,
expected
);
assert_eq!
(
result
,
expected
);
}
}
#[test]
fn
moins
()
{
let
operation
=
Operation
::
Moins
(
4
,
5
);
let
result
=
OperationResult
::
from
(
operation
);
let
expected
=
OperationResult
::
new
(
"4 - 5"
,
-
1
);
assert_eq!
(
result
,
expected
);
}
}
}
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