-
Notifications
You must be signed in to change notification settings - Fork 145
/
Copy pathregular_numbers_test.go
47 lines (38 loc) · 1.04 KB
/
regular_numbers_test.go
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
package heap
import (
"slices"
"testing"
)
/*
TestRegularNumbers tests solution(s) with the following signature and problem description:
func RegularNumbers(n int) []int
Regular numbers are numbers whose only prime divisors are 2, 3, and 5.
For example 24 is a regular number because it can be factored into 2^3 * 3^1 * 5^0.
Given a positive integer n, return first n regular numbers.
For example given n=4:
1 = 2^0
2 = 2^1
3 = 3^1
4 = 2^2
So the first 3 regular numbers are {1, 2, 3, 4}.
*/
func TestRegularNumbers(t *testing.T) {
tests := []struct {
n int
regularNumbers []int
}{
{0, []int{}},
{1, []int{1}},
{2, []int{1, 2}},
{3, []int{1, 2, 3}},
{4, []int{1, 2, 3, 4}},
{5, []int{1, 2, 3, 4, 5}},
{10, []int{1, 2, 3, 4, 5, 6, 8, 9, 10, 12}},
{15, []int{1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 16, 18, 20, 24}},
}
for i, test := range tests {
if got := RegularNumbers(test.n); !slices.Equal(got, test.regularNumbers) {
t.Fatalf("Failed test case #%d. Want %v got %d", i, test.regularNumbers, got)
}
}
}