-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
531ac45
commit fdb9a85
Showing
7 changed files
with
193 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,47 @@ | ||
// - Activity 001 - Create the substraction (-) function and test it | ||
|
||
fn sub (x:Int , y:Int) -> Int{ | ||
x-y | ||
fn sub(x: Int, y: Int) -> Int { | ||
x - y | ||
} | ||
|
||
test sub_test(){ | ||
sub(5,2) ==3 | ||
test sub_test() { | ||
sub(5, 2) == 3 | ||
} | ||
|
||
fn sum(x,y) -> Int { | ||
x+y | ||
fn sum(x, y) -> Int { | ||
x + y | ||
} | ||
|
||
|
||
//- Activity 002 - Create the multiplication (*) function and test it | ||
|
||
fn mul(x:Int, y :Int) -> Int{ | ||
x*y | ||
fn mul(x: Int, y: Int) -> Int { | ||
x * y | ||
} | ||
|
||
test mul_test(){ | ||
mul(5,2) == 10 | ||
test mul_test() { | ||
mul(5, 2) == 10 | ||
} | ||
|
||
// - Activity 003 - Create the division (/) function and test it | ||
|
||
|
||
fn divd(x,y) { | ||
x/y | ||
fn divd(x, y) { | ||
x / y | ||
} | ||
|
||
test divd_test(){ | ||
divd(10,5) == 2 | ||
test divd_test() { | ||
divd(10, 5) == 2 | ||
} | ||
|
||
//- Activity 004 - Modify the main function that uses the sum function and the new functions created in the previous practices and test it | ||
|
||
fn main() { | ||
let result = sum (2,3) | ||
let result = sub(result,1) | ||
let result = mul(result,2) | ||
let result = divd (result,2) | ||
result | ||
let result = sum(2, 3) | ||
let result = sub(result, 1) | ||
let result = mul(result, 2) | ||
let result = divd(result, 2) | ||
result | ||
} | ||
|
||
test main_test(){ | ||
main()==4 | ||
} | ||
test main_test() { | ||
main() == 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,10 @@ validator alwaysSucceeds { | |
) { | ||
True | ||
} | ||
|
||
else(_) { | ||
fail | ||
} | ||
} | ||
|
||
test tes_always_successful() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,27 @@ | ||
fn main() { | ||
let x =5 | ||
let y =6 | ||
let z =x+y | ||
x + y +z | ||
let x = 5 | ||
let y = 6 | ||
let z = x + y | ||
x + y + z | ||
} | ||
|
||
fn sum (x ,y)-> Int{ | ||
x+y | ||
fn sum(x, y) -> Int { | ||
x + y | ||
} | ||
|
||
fn sub (a: Int, b: Int)-> Int{ | ||
a-b | ||
fn sub(a: Int, b: Int) -> Int { | ||
a - b | ||
} | ||
|
||
test main_test() { | ||
main() ==22 | ||
main() == 22 | ||
} | ||
|
||
test sum_test(){ | ||
sum(10,11) == 21 | ||
test sum_test() { | ||
sum(10, 11) == 21 | ||
} | ||
|
||
//we are failing this by not putting the expected value , (5-3=2, we put 21, so it failing) | ||
test sub_test(){ | ||
sub(5,3) == 2 | ||
} | ||
test sub_test() { | ||
sub(5, 3) == 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
fn even_odd_bool(x: Int) -> Bool { | ||
if x % 2 == 0 { | ||
True | ||
} else { | ||
False | ||
} | ||
} | ||
|
||
test even_odd_bool_test() { | ||
even_odd_bool(10) == True | ||
} | ||
|
||
fn even_odd_number(x: Int) -> Int { | ||
if x % 2 == 0 { | ||
1 | ||
} else { | ||
0 | ||
} | ||
} | ||
|
||
test even_odd_number_test() { | ||
even_odd_number(10) == 1 | ||
} | ||
|
||
fn even_odd_when(x: Int) -> Bool { | ||
when x % 2 is { | ||
0 -> True | ||
_ -> False | ||
} | ||
} | ||
|
||
test even_odd_when_test() { | ||
even_odd_when(2) | ||
} | ||
|
||
fn even(x: Int) -> Bool { | ||
x % 2 == 0 | ||
} | ||
|
||
fn odd(x: Int) -> Bool { | ||
!even(x) | ||
} | ||
|
||
test even_odd_test_optimise() { | ||
let number = 3 | ||
|
||
if even(number) { | ||
True | ||
} else { | ||
odd(number) | ||
} | ||
} | ||
|
||
test even_odd_test() { | ||
let number = 3 | ||
|
||
let is_even_or_odd = even(number) || odd(number) | ||
|
||
expect is_even_or_odd | ||
} | ||
|
||
// compares prices vs payment and answer True if payment >= price, | ||
//and False if not. | ||
|
||
fn price(price: Int, payment: Int) -> Bool { | ||
payment >= price | ||
} | ||
|
||
test price_test_pass() { | ||
price(10, 12) | ||
} | ||
|
||
test price_test_fail() { | ||
price(100, 12) | ||
} |
Oops, something went wrong.