2019-06-29 18:24:55 +03:00
|
|
|
import math
|
|
|
|
|
2019-06-29 23:49:57 +03:00
|
|
|
fn test_gcd() {
|
2019-06-29 18:24:55 +03:00
|
|
|
assert math.gcd(6, 9) == 3
|
|
|
|
assert math.gcd(6, -9) == 3
|
2019-06-29 23:49:57 +03:00
|
|
|
assert math.gcd(-6, -9) == 3
|
|
|
|
assert math.gcd(0, 0) == 0
|
|
|
|
}
|
2019-06-29 18:24:55 +03:00
|
|
|
|
2019-06-29 23:49:57 +03:00
|
|
|
fn test_lcm() {
|
2019-06-29 18:24:55 +03:00
|
|
|
assert math.lcm(2, 3) == 6
|
|
|
|
assert math.lcm(-2, 3) == 6
|
2019-06-29 23:49:57 +03:00
|
|
|
assert math.lcm(-2, -3) == 6
|
|
|
|
assert math.lcm(0, 0) == 0
|
2019-06-29 18:24:55 +03:00
|
|
|
}
|
2019-07-02 13:50:33 +03:00
|
|
|
|
|
|
|
fn test_digits() {
|
|
|
|
digits_in_10th_base := math.digits(125, 10)
|
|
|
|
assert digits_in_10th_base[0] == 5
|
|
|
|
assert digits_in_10th_base[1] == 2
|
|
|
|
assert digits_in_10th_base[2] == 1
|
|
|
|
|
|
|
|
digits_in_16th_base := math.digits(15, 16)
|
|
|
|
assert digits_in_16th_base[0] == 15
|
|
|
|
|
|
|
|
negative_digits := math.digits(-4, 2)
|
|
|
|
assert negative_digits[2] == -1
|
|
|
|
}
|
|
|
|
|
2019-11-06 18:04:48 +03:00
|
|
|
/*
|
2019-07-02 13:50:33 +03:00
|
|
|
fn test_factorial() {
|
2019-07-17 01:03:51 +03:00
|
|
|
assert math.factorial(12) == 479001600
|
2019-07-02 13:50:33 +03:00
|
|
|
assert math.factorial(5) == 120
|
|
|
|
assert math.factorial(0) == 1
|
|
|
|
}
|
2019-11-06 18:04:48 +03:00
|
|
|
*/
|
2019-07-12 08:46:40 +03:00
|
|
|
|
|
|
|
fn test_erf() {
|
|
|
|
assert math.erf(0) == 0
|
2019-09-29 18:27:53 +03:00
|
|
|
assert math.erf(1.5) + math.erf(-1.5) == 0
|
2019-07-12 08:46:40 +03:00
|
|
|
assert math.erfc(0) == 1
|
2019-09-29 18:27:53 +03:00
|
|
|
assert math.erf(2.5) + math.erfc(2.5) == 1
|
|
|
|
assert math.erfc(3.6) + math.erfc(-3.6) == 2
|
2019-07-12 08:46:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fn test_gamma() {
|
|
|
|
assert math.gamma(1) == 1
|
|
|
|
assert math.gamma(5) == 24
|
2019-09-29 18:27:53 +03:00
|
|
|
assert math.log_gamma(4.5) == math.log(math.gamma(4.5))
|
2019-07-12 08:46:40 +03:00
|
|
|
}
|
2019-11-06 18:04:48 +03:00
|
|
|
|
|
|
|
fn test_mod() {
|
|
|
|
assert 4 % 2 == 0
|
|
|
|
x := 2
|
|
|
|
assert u64(5) % x == 1
|
2019-11-06 20:47:03 +03:00
|
|
|
mut a := 10
|
|
|
|
a %= 2
|
|
|
|
assert a == 0
|
2019-11-06 18:04:48 +03:00
|
|
|
}
|