-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharguments_optional.rs
More file actions
51 lines (42 loc) 路 1.03 KB
/
Copy patharguments_optional.rs
File metadata and controls
51 lines (42 loc) 路 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Create a function that sums two arguments together. If only one argument is provided,
// then return a function that expects one argument and returns the sum.
//
// For example, addTogether(2, 3) should return 5, and addTogether(2) should return a function.
//
// Calling this returned function with a single argument will then return the sum:
//
// var sumTwoAnd = addTogether(2);
//
// sumTwoAnd(3) returns 5.
//
// If either argument isn't a valid number, return undefined.
#[allow(dead_code)]
fn curry(a: i32) -> impl Fn(i32) -> i32 {
move |x| a + x
}
#[allow(dead_code)]
fn add_two(a: i32, b: i32) -> i32 {
a + b
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test1() {
assert_eq!(add_two(2, 3), 5);
}
#[test]
fn test2() {
assert_eq!(add_two(23, 30), 53);
}
#[test]
fn test3() {
let add_five = curry(5);
assert_eq!(add_five(7), 12);
}
#[test]
fn test4() {
let add_twentyfive = curry(25);
assert_eq!(add_twentyfive(50), 75);
}
}