From 90eda2d41d028b2ae792c015adaef782fc4e30ea Mon Sep 17 00:00:00 2001 From: "julio.cesar" Date: Mon, 19 Oct 2020 19:05:49 -0300 Subject: [PATCH] test: add tests for factorial and fastpow --- numerical/factorial_test.go | 23 +++++++++++++++++++++++ numerical/fast_pow_test.go | 23 +++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 numerical/factorial_test.go create mode 100644 numerical/fast_pow_test.go diff --git a/numerical/factorial_test.go b/numerical/factorial_test.go new file mode 100644 index 0000000..1c3c364 --- /dev/null +++ b/numerical/factorial_test.go @@ -0,0 +1,23 @@ +package numerical + +import "testing" + +// Testfactorial tests factorial function +func Testfactorial(t *testing.T) { + + if factorial(2) != 2 { + t.Error("[Error] factorial(2) is wrong") + } + + if factorial(3) != 6 { + t.Error("[Error] factorial(3) is wrong") + } + + if factorial(0) != 1 { + t.Error("[Error] factorial(0) is wrong") + } + + if factorial(5) != 120 { + t.Error("[Error] factorial(5) is wrong") + } +} diff --git a/numerical/fast_pow_test.go b/numerical/fast_pow_test.go new file mode 100644 index 0000000..1def84b --- /dev/null +++ b/numerical/fast_pow_test.go @@ -0,0 +1,23 @@ +package numerical + +import "testing" + +// TestFastPow tests fastpow function +func TestFastPow(t *testing.T) { + + if FastPow(2, 10) != 1024 { + t.Error("[Error] FastPow(2, 10) is wrong") + } + + if FastPow(1, 10) != 1 { + t.Error("[Error] FastPow(1, 10) is wrong") + } + + if FastPow(0, 15) != 0 { + t.Error("[Error] FastPow(0, 15) is wrong") + } + + if FastPow(10, 2) != 100 { + t.Error("[Error] FastPow(0, 15) is wrong") + } +}