This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func isTrue(t *testing.T, b bool) { | |
t.Helper() | |
if !b { | |
t.Fatal() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func TestLastIndex(t *testing.T) { | |
tableTests := []struct { | |
name string | |
list []int | |
x int | |
want int | |
}{ | |
{name: "singleElement", list: []int{1}, x: 1, want: 0}, | |
{name: "2timesTheSame", list: []int{1, 1}, x: 1, want: 1}, | |
{name: "notFound", list: []int{1, 1, 1, 2, 2, 1}, x: 3, want: -1}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "testing" | |
func TestLastIndex(t *testing.T) { | |
list := []int{1, 2, 1, 1} | |
if got := lastIndex(list, 2); got != 1 { | |
t.Errorf("LastIndex(%v, %v) = %v, want %v", list, 2, got, 1) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func main() { | |
list := []int{1, 2, 3, 3, 8, 4, 5} | |
lastIndexOfFive := LastIndex(list, 5) | |
fmt.Printf("the last index of %d in the list %v is: %d", | |
5, list, lastIndexOfFive) |