Skip to content

Commit

Permalink
Update: test
Browse files Browse the repository at this point in the history
  • Loading branch information
awesee committed Nov 15, 2019
1 parent 42a34e7 commit 963ebd2
Show file tree
Hide file tree
Showing 219 changed files with 3,575 additions and 3,575 deletions.
20 changes: 10 additions & 10 deletions internal/leetcode/question_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,22 +332,22 @@ const testTpl = `package {{packageName}}
import "testing"
type caseType struct {
input int
expected int
type testType struct {
in int
want int
}
func Test{{funcName}}(t *testing.T) {
tests := [...]caseType{
tests := [...]testType{
{
input: 0,
expected: 0,
in: 0,
want: 0,
},
}
for _, tc := range tests {
output := 0
if output != tc.expected {
t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected)
for _, tt := range tests {
got := 0
if got != tt.want {
t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want)
}
}
}
Expand Down
24 changes: 12 additions & 12 deletions problems/01-matrix/01_matrix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,42 @@ import (
"testing"
)

type caseType struct {
input [][]int
expected [][]int
type testType struct {
in [][]int
want [][]int
}

func TestUpdateMatrix(t *testing.T) {
tests := [...]caseType{
tests := [...]testType{
{
input: [][]int{
in: [][]int{
{0, 0, 0},
{0, 1, 0},
{0, 0, 0},
},
expected: [][]int{
want: [][]int{
{0, 0, 0},
{0, 1, 0},
{0, 0, 0},
},
},
{
input: [][]int{
in: [][]int{
{0, 0, 0},
{0, 1, 0},
{1, 1, 1},
},
expected: [][]int{
want: [][]int{
{0, 0, 0},
{0, 1, 0},
{1, 2, 1},
},
},
}
for _, tc := range tests {
output := updateMatrix(tc.input)
if !reflect.DeepEqual(output, tc.expected) {
t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected)
for _, tt := range tests {
got := updateMatrix(tt.in)
if !reflect.DeepEqual(got, tt.want) {
t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@ package problem717

import "testing"

type caseType struct {
input []int
expected bool
type testType struct {
in []int
want bool
}

func TestIsOneBitCharacter(t *testing.T) {
tests := [...]caseType{
tests := [...]testType{
{
input: []int{1, 0, 0},
expected: true,
in: []int{1, 0, 0},
want: true,
},
{
input: []int{1, 1, 1, 0},
expected: false,
in: []int{1, 1, 1, 0},
want: false,
},
}
for _, tc := range tests {
output := isOneBitCharacter(tc.input)
if output != tc.expected {
t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected)
for _, tt := range tests {
got := isOneBitCharacter(tt.in)
if got != tt.want {
t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want)
}
}
}
28 changes: 14 additions & 14 deletions problems/132-pattern/132_pattern_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@ package problem456

import "testing"

type caseType struct {
input []int
expected bool
type testType struct {
in []int
want bool
}

func TestFind132pattern(t *testing.T) {
tests := [...]caseType{
tests := [...]testType{
{
input: []int{1, 2, 3, 4},
expected: false,
in: []int{1, 2, 3, 4},
want: false,
},
{
input: []int{3, 1, 4, 2},
expected: true,
in: []int{3, 1, 4, 2},
want: true,
},
{
input: []int{-1, 3, 2, 0},
expected: true,
in: []int{-1, 3, 2, 0},
want: true,
},
}
for _, tc := range tests {
output := find132pattern(tc.input)
if output != tc.expected {
t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected)
for _, tt := range tests {
got := find132pattern(tt.in)
if got != tt.want {
t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want)
}
}
}
32 changes: 16 additions & 16 deletions problems/2-keys-keyboard/2_keys_keyboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,34 @@ package problem650

import "testing"

type caseType struct {
input int
expected int
type testType struct {
in int
want int
}

func TestMinSteps(t *testing.T) {
tests := [...]caseType{
tests := [...]testType{
{
input: 1,
expected: 0,
in: 1,
want: 0,
},
{
input: 3,
expected: 3,
in: 3,
want: 3,
},
{
input: 30,
expected: 10,
in: 30,
want: 10,
},
{
input: 97,
expected: 97,
in: 97,
want: 97,
},
}
for _, tc := range tests {
output := minSteps(tc.input)
if output != tc.expected {
t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected)
for _, tt := range tests {
got := minSteps(tt.in)
if got != tt.want {
t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want)
}
}
}
24 changes: 12 additions & 12 deletions problems/24-game/24_game_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@ package problem679

import "testing"

type caseType struct {
input []int
expected bool
type testType struct {
in []int
want bool
}

func TestJudgePoint24(t *testing.T) {
tests := [...]caseType{
tests := [...]testType{
{
input: []int{4, 1, 8, 7},
expected: true,
in: []int{4, 1, 8, 7},
want: true,
},
{
input: []int{1, 2, 1, 2},
expected: false,
in: []int{1, 2, 1, 2},
want: false,
},
}
for _, tc := range tests {
output := judgePoint24(tc.input)
if output != tc.expected {
t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected)
for _, tt := range tests {
got := judgePoint24(tt.in)
if got != tt.want {
t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want)
}
}
}
48 changes: 24 additions & 24 deletions problems/3sum-closest/3sum_closest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,44 @@ package problem16

import "testing"

type caseType struct {
input []int
target int
expected int
type testType struct {
in []int
target int
want int
}

func TestThreeSumClosest(t *testing.T) {
tests := [...]caseType{
tests := [...]testType{
{
input: []int{-1, 2, 1, -4},
target: 1,
expected: 2,
in: []int{-1, 2, 1, -4},
target: 1,
want: 2,
},
{
input: []int{-1, 0, 1, 2, -1, -4},
target: 1,
expected: 1,
in: []int{-1, 0, 1, 2, -1, -4},
target: 1,
want: 1,
},
{
input: []int{0, 0, 0, 0},
target: 1,
expected: 0,
in: []int{0, 0, 0, 0},
target: 1,
want: 0,
},
{
input: []int{-2, 0, 0, 2, 2, 2},
target: 2,
expected: 2,
in: []int{-2, 0, 0, 2, 2, 2},
target: 2,
want: 2,
},
{
input: []int{-2, 0, 0, 2, 2, 2, 2},
target: 1,
expected: 0,
in: []int{-2, 0, 0, 2, 2, 2, 2},
target: 1,
want: 0,
},
}
for _, tc := range tests {
output := threeSumClosest(tc.input, tc.target)
if output != tc.expected {
t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected)
for _, tt := range tests {
got := threeSumClosest(tt.in, tt.target)
if got != tt.want {
t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want)
}
}
}
32 changes: 16 additions & 16 deletions problems/3sum/3sum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,43 @@ import (
"testing"
)

type caseType struct {
input []int
expected [][]int
type testType struct {
in []int
want [][]int
}

func TestThreeSum(t *testing.T) {
tests := [...]caseType{
tests := [...]testType{
{
input: []int{-1, 0, 1, 2, -1, -4},
expected: [][]int{
in: []int{-1, 0, 1, 2, -1, -4},
want: [][]int{
{-1, -1, 2},
{-1, 0, 1},
},
},
{
input: []int{0, 0, 0, 0},
expected: [][]int{
in: []int{0, 0, 0, 0},
want: [][]int{
{0, 0, 0},
},
},
{
input: []int{-2, 0, 0, 2, 2, 2},
expected: [][]int{
in: []int{-2, 0, 0, 2, 2, 2},
want: [][]int{
{-2, 0, 2},
},
},
{
input: []int{-2, 0, 0, 2, 2, 2, 2},
expected: [][]int{
in: []int{-2, 0, 0, 2, 2, 2, 2},
want: [][]int{
{-2, 0, 2},
},
},
}
for _, tc := range tests {
output := threeSum(tc.input)
if !reflect.DeepEqual(output, tc.expected) {
t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected)
for _, tt := range tests {
got := threeSum(tt.in)
if !reflect.DeepEqual(got, tt.want) {
t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want)
}
}
}
Loading

0 comments on commit 963ebd2

Please sign in to comment.