aboutsummaryrefslogtreecommitdiffstats
path: root/utils_test.go
blob: 7b912a0886ba1158960601d1e844719bab0ac1f6 (plain)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main

import (
	"fmt"
	"sort"
	"testing"
)

func TestLog(t *testing.T) {
	tests := []struct {
		input    int64
		expected int64
	}{
		{1, 0},
		{2, 1},
		{0, 0},
		{3, 1},
		{4, 2},
	}
	for _, test := range tests {
		actual := Log(test.input)
		if test.expected != actual {
			t.Errorf("%d, expected: %d, actual: %d", test.input, test.expected,
				actual)
		}
	}
}

func TestPow(t *testing.T) {
	tests := []struct {
		x        int64
		n        int64
		expected int64
	}{
		{1, 0, 1},
		{2, 0, 1},
		{0, 0, 1},
		{0, 2, 0},
		{1, 1, 1},
		{1, 2, 1},
		{2, 1, 2},
		{2, 2, 4},
		{2, 3, 8},
		{3, 2, 9},
		{6, 7, 279936},
	}
	for _, test := range tests {
		actual := Pow(test.x, test.n)
		if test.expected != actual {
			t.Errorf("%d**%d, expected: %d, actual: %d", test.x, test.n,
				test.expected, actual)
		}
	}

}

func TestPost(t *testing.T) {
	tests := []struct {
		size     int64
		height   int64
		id       int64
		expected int64
	}{
		{14, 4, 7, 0},
		{14, 4, 8, 1},
		{14, 4, 3, 2},
		{14, 4, 5, 9},
		{14, 4, 0, 14},
	}
	for _, test := range tests {
		actual := Post(test.size, test.height, test.id)
		if test.expected != actual {
			t.Errorf("%d, %d, expected: %d, actual: %d", test.size, test.id,
				test.expected, actual)
		}
	}

}

func TestShuffle(t *testing.T) {
	a := sort.IntSlice([]int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9})
	Shuffle(a)
	fmt.Println(a)
}