You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cses/introductory_test.go

41 lines
1.3 KiB
Go

package cses
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestWeirdAlgo(t *testing.T) {
assert.Equal(t, "[3 10 5 16 8 4 2 1]", WeirdAlgo(3))
}
func TestMissingNumber(t *testing.T) {
assert.Equal(t, 4, MissingNumber(5, []int{2, 3, 1, 5}))
assert.Equal(t, 7, MissingNumber(9, []int{2, 3, 1, 5, 4, 6, 9, 8}))
}
func TestRepetitions(t *testing.T) {
assert.Equal(t, 0, Repetitions(""))
assert.Equal(t, 3, Repetitions("ATTCGGGA"))
assert.Equal(t, 4, Repetitions("AGGTTCGGGGA"))
}
func TestIncreasingArray(t *testing.T) {
assert.Equal(t, 0, IncreasingArray(5, []int{}))
assert.Equal(t, 0, IncreasingArray(5, []int{3}))
assert.Equal(t, 5, IncreasingArray(5, []int{3, 2, 5, 1, 7}))
}
func TestBeautifulPermutations(t *testing.T) {
assert.Equal(t, "NO SOLUTION", BeautifulPermutations(2))
assert.Equal(t, "NO SOLUTION", BeautifulPermutations(3))
assert.Equal(t, "[3 1 4 2]", BeautifulPermutations(4))
assert.Equal(t, "[5 3 1 4 2]", BeautifulPermutations(5))
assert.Equal(t, "[6 4 2 5 3 1]", BeautifulPermutations(6))
assert.Equal(t, "[7 5 3 1 6 4 2]", BeautifulPermutations(7))
assert.Equal(t, "[8 6 4 2 7 5 3 1]", BeautifulPermutations(8))
assert.Equal(t, "[9 7 5 3 1 8 6 4 2]", BeautifulPermutations(9))
assert.Equal(t, 48895, len(BeautifulPermutations(10000)))
}