|
@@ -0,0 +1,31 @@
|
|
|
+package main
|
|
|
+
|
|
|
+import (
|
|
|
+ "testing"
|
|
|
+)
|
|
|
+
|
|
|
+func TestDistanceOnTwoIds(t *testing.T) {
|
|
|
+ cases := []struct {
|
|
|
+ Name string
|
|
|
+ Left, Right []int
|
|
|
+ Expected int
|
|
|
+ }{
|
|
|
+ {"d(3, 4) = 1", []int{3}, []int{4}, 1},
|
|
|
+ {"d(4, 3) = 1", []int{4}, []int{3}, 1},
|
|
|
+ {"d(2, 5) = 3", []int{2}, []int{5}, 3},
|
|
|
+ {"d(1, 3) = 2", []int{1}, []int{3}, 2},
|
|
|
+ {"d(3, 9) = 6", []int{3}, []int{9}, 6},
|
|
|
+ {"d(3, 3) = 0", []int{3}, []int{3}, 0},
|
|
|
+ {"d([3,4,2,1,3,3], [4,3,5,3,9,3]) = 11",
|
|
|
+ []int{3, 4, 2, 1, 3, 3},
|
|
|
+ []int{4, 3, 5, 3, 9, 3},
|
|
|
+ 11,
|
|
|
+ },
|
|
|
+ }
|
|
|
+ for _, c := range cases {
|
|
|
+ actual := distance(c.Left, c.Right)
|
|
|
+ if actual != c.Expected {
|
|
|
+ t.Errorf("Expected %s; got %d", c.Name, actual)
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|