#returned values are same but the test fails

22 messages · Page 1 of 1 (latest)

charred charm
#

line 39 of main_test.go

broken cypress
#

they r different types

#

map[main.voter_name]main.voter_ranks
vs
main.global_ranks

charred charm
#

hmmm

charred charm
#

its the test_pair that returns false

charred charm
broken cypress
#

use reflect.TypeOf to log the types of each

charred charm
broken cypress
#

those two need to be equal for reflect.DeepEqual to return true

charred charm
#
func make_pairs(unpaired_slice []string) (pairs [][]string) {
    for i, v := range unpaired_slice {
        pairs_slice := unpaired_slice[i+1:]
        if len(pairs_slice) == 0 {
            break
        }
        for _, x := range pairs_slice {
            pairs = append(pairs, []string{v, x})
        }
    }

    return pairs
}
#
func Test_make_pairs(t *testing.T) {
    s := []string{"a", "b", "c"}
    expect := [][]string{{"a", "b"}, {"a", "c"}, {"b", "c"}}
    get := make_pairs(s)
    expections(t, expect, get, true)
}
#

i dont see how that those types are relavent here

#

im just using strings in this test

#
func expections(t testing.TB, expect, got interface{}, deep bool) {
    t.Helper()
    if !deep {
        if got != expect {
            t.Errorf("Got: %v \nWant: %v", got, expect)
        }
    } else {
        if reflect.DeepEqual(expect, got) {
            t.Errorf("Got: %v \nWant: %v", got, expect)
        }
    }
}

#

oh

#

wait

#

LMAO

#

i messed my expectations func

#

@broken cypress thanks for catching that

#

i forgot to add ! in my helper func