aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--exercises/slices/slices4/main_test.go39
-rw-r--r--info.toml6
2 files changed, 45 insertions, 0 deletions
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)
+ }
+}
diff --git a/info.toml b/info.toml
index a4104ec..f8cffd7 100644
--- a/info.toml
+++ b/info.toml
@@ -173,3 +173,9 @@ Add some elements and read the output.
If you are still confuse about the append function, don't worry, check out
the spec: https://go.dev/ref/spec#Appending_and_copying_slices"""
+
+[[exercises]]
+name = "slices4"
+path = "exercises/slices/slices4/main.go"
+mode = "test"
+hint = "No hints this time"