From 525d58dc41bf3d92427b53892a5b676c9ce00926 Mon Sep 17 00:00:00 2001 From: MaurĂ­cio Antunes Date: Mon, 21 Nov 2022 18:45:15 -0300 Subject: feat: add test exercise for slices --- exercises/slices/slices4/main_test.go | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 exercises/slices/slices4/main_test.go (limited to 'exercises') diff --git a/exercises/slices/slices4/main_test.go b/exercises/slices/slices4/main_test.go new file mode 100644 index 0000000..4723418 --- /dev/null +++ b/exercises/slices/slices4/main_test.go @@ -0,0 +1,39 @@ +// slices4 +// Make me compile! + +// I AM NOT DONE +package main_test + +import ( + "reflect" + "testing" +) + +func TestGetOnlyFirstName(t *testing.T) { + names := []string{"John", "Maria", "Carl", "Peter"} + firstName := names[3] + + if firstName != "John" { + t.Errorf("firstName value must be John") + } +} + +func TestGetFirstTwoNames(t *testing.T) { + names := []string{"John", "Maria", "Carl", "Peter"} + firstTwoNames := names[5:10] + expectedFirstTwoNames := []string{"John", "Maria"} + + if !reflect.DeepEqual(firstTwoNames, expectedFirstTwoNames) { + t.Errorf("firstTwoNames should be %v, but got %v", expectedFirstTwoNames, firstTwoNames) + } +} + +func TestGetLastTwoNames(t *testing.T) { + names := []string{"John", "Maria", "Carl", "Peter"} + lastTwoNames := names[5:10] + expectedLastTwoNames := []string{"Carl", "Peter"} + + if !reflect.DeepEqual(lastTwoNames, expectedLastTwoNames) { + t.Errorf("firstTwoNames should be %v, but got %v", expectedLastTwoNames, lastTwoNames) + } +} -- cgit v1.2.3-70-g09d2