aboutsummaryrefslogtreecommitdiff
path: root/lib/math/math_test.go
diff options
context:
space:
mode:
authorShulhan <m.shulhan@gmail.com>2020-03-12 14:48:47 +0700
committerShulhan <m.shulhan@gmail.com>2020-03-12 14:52:53 +0700
commit889c4a27d4e806f8c662764f0eb344f3804e09a7 (patch)
treead7954e0d247a078d122e362b2987299ea34fb8b /lib/math/math_test.go
parent975e4843f0f18ecff9c5ca323e84aa14d5591a88 (diff)
downloadpakakeh.go-889c4a27d4e806f8c662764f0eb344f3804e09a7.tar.xz
mining/math: move the package from "lib/mining/" to "lib/" directory
Diffstat (limited to 'lib/math/math_test.go')
-rw-r--r--lib/math/math_test.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/lib/math/math_test.go b/lib/math/math_test.go
new file mode 100644
index 00000000..ae7bf563
--- /dev/null
+++ b/lib/math/math_test.go
@@ -0,0 +1,48 @@
+// Copyright 2015 Mhd Sulhan <ms@kilabit.info>. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package math
+
+import (
+ "testing"
+)
+
+func TestFactorial(t *testing.T) {
+ in := []int{-3, -2, -1, 0, 1, 2, 3}
+ exp := []int{-6, -2, -1, 1, 1, 2, 6}
+
+ for i := range in {
+ res := Factorial(in[i])
+
+ if res != exp[i] {
+ t.Fatal("Expecting ", exp[i], ", got ", res)
+ }
+ }
+}
+
+func TestBinomialCoefficient(t *testing.T) {
+ in := [][]int{{1, 2}, {1, 1}, {3, 2}, {5, 3}}
+ exp := []int{0, 1, 3, 10}
+
+ for i := range in {
+ res := BinomialCoefficient(in[i][0], in[i][1])
+
+ if res != exp[i] {
+ t.Fatal("Expecting ", exp[i], ", got ", res)
+ }
+ }
+}
+
+func TestStirlingS2(t *testing.T) {
+ in := [][]int{{3, 1}, {3, 2}, {3, 3}, {5, 3}}
+ exp := []int{1, 3, 1, 25}
+
+ for i := range in {
+ res := StirlingS2(in[i][0], in[i][1])
+
+ if res != exp[i] {
+ t.Fatal("Expecting ", exp[i], ", got ", res)
+ }
+ }
+}