Skip to content

Commit

Permalink
create separate_cases_file test data
Browse files Browse the repository at this point in the history
  • Loading branch information
meoconbatu committed Oct 15, 2023
1 parent 21b939f commit 96e2c00
Show file tree
Hide file tree
Showing 10 changed files with 299 additions and 234 deletions.
4 changes: 4 additions & 0 deletions integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ func TestIntegration(t *testing.T) {
inputDir: filepath.Join("testrunner", "testdata", "practice", "pkg_level_error"),
expected: filepath.Join("testrunner", "testdata", "expected", "pkg_level_error.json"),
},
{
inputDir: filepath.Join("testrunner", "testdata", "practice", "separate_cases_file"),
expected: filepath.Join("testrunner", "testdata", "expected", "separate_cases_file.json"),
},
{
inputDir: filepath.Join("testrunner", "testdata", "practice", "failing"),
expected: filepath.Join("testrunner", "testdata", "expected", "failing.json"),
Expand Down
107 changes: 0 additions & 107 deletions testrunner/extract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,6 @@ func TestExtractTestCode(t *testing.T) {
}`,
},
}
tests = append(tests, testsDataSeparate...)
tests = append(tests, testsMultiAssignStmt...)
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
code, _ := ExtractTestCodeAndTaskID(rootLevelTestsMap, tt.testName)
Expand Down Expand Up @@ -243,108 +241,3 @@ func TestExtractTestCode(t *testing.T) {
})
}
}

var testsDataSeparate = []struct {
name string
testName string
testFile string
code string
}{
{
name: "working subtest with separate test data",
testName: "TestParseCard_Separate/parse_jack",
testFile: filepath.Join("testdata", "concept", "conditionals", "conditionals_test.go"),
code: `func TestParseCard_Separate(t *testing.T) {
tt := struct {
name string
card string
want int
}{
name: "parse jack",
card: "jack",
want: 10,
}
if got := ParseCard(tt.card); got != tt.want {
t.Errorf("ParseCard(%s) = %d, want %d", tt.card, got, tt.want)
}
}`,
}, {
name: "missing / not found subtest with separate test data",
testName: "TestParseCard_Separate/parse_missing_subtests",
testFile: filepath.Join("testdata", "concept", "conditionals", "conditionals_test.go"),
code: `func TestParseCard_Separate(t *testing.T) {
for _, tt := range testcases {
t.Run(tt.name, func(t *testing.T) {
if got := ParseCard(tt.card); got != tt.want {
t.Errorf("ParseCard(%s) = %d, want %d", tt.card, got, tt.want)
}
})
}
}`,
}, {
name: "multiple statements with separate test data",
testName: "TestBlackjack_Separate/blackjack_with_ten_(ace_first)",
testFile: filepath.Join("testdata", "concept", "conditionals", "conditionals_test.go"),
code: `func TestBlackjack_Separate(t *testing.T) {
tt := struct {
name string
hand hand
want bool
}{
name: "blackjack with ten (ace first)",
hand: hand{card1: "ace", card2: "ten"},
want: true,
}
someAssignment := "test"
fmt.Println(someAssignment)
_ = "literally anything"
got := IsBlackjack(tt.hand.card1, tt.hand.card2)
if got != tt.want {
t.Errorf("IsBlackjack(%s, %s) = %t, want %t", tt.hand.card1, tt.hand.card2, got, tt.want)
}
// Additional statements should be included
fmt.Println("the whole block")
fmt.Println("should be returned")
}`,
},
}
var testsMultiAssignStmt = []struct {
name string
testName string
testFile string
code string
}{
{
name: "subtest with arbitrary test data variable name, additional assign statements above and below test data",
testName: "TestSubtest_MultiAssignStmt/parse_king",
testFile: filepath.Join("testdata", "concept", "conditionals", "conditionals_test.go"),
code: `func TestSubtest_MultiAssignStmt(t *testing.T) {
someAssignment := "test"
tt := struct {
name string
card string
want int
}{
name: "parse king",
card: "king",
want: 10,
}
someAssignment2 := "test2"
if got := ParseCard(tt.card); got != tt.want {
t.Errorf("ParseCard(%s) = %d, want %d", tt.card, got, tt.want)
}
// Additional statements should be included
fmt.Println("the whole block")
fmt.Println("should be returned")
}`,
},
}
59 changes: 0 additions & 59 deletions testrunner/testdata/concept/conditionals/cases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,62 +19,3 @@ var allergicToTests = []struct {
expected: false,
},
}
var testcases = []struct {
name string
card string
want int
}{
{
name: "parse two",
card: "two",
want: 2,
},
{
name: "parse jack",
card: "jack",
want: 10,
},
{
name: "parse king",
card: "king",
want: 10,
},
}

type hand struct {
card1, card2 string
}

var testcases2 = []struct {
name string
hand hand
want bool
}{
{
name: "blackjack with ten (ace first)",
hand: hand{card1: "ace", card2: "ten"},
want: true,
},
{
name: "blackjack with jack (ace first)",
hand: hand{card1: "ace", card2: "jack"},
want: true,
},
{
name: "blackjack with queen (ace first)",
hand: hand{
card1: "ace", card2: "queen"
},
want: true,
},
{
name: "blackjack with king (ace first)",
hand: hand{card1: "ace", card2: "king"},
want: true,
},
{
name: "no blackjack with eight and five",
hand: hand{card2: "eight", card1: "five"},
want: false,
},
}
68 changes: 0 additions & 68 deletions testrunner/testdata/concept/conditionals/conditionals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,71 +143,3 @@ func TestBlackjack(t *testing.T) {
fmt.Println("the whole block")
fmt.Println("should be returned")
}
func TestParseCard_Separate(t *testing.T) {
for _, tt := range testcases {
t.Run(tt.name, func(t *testing.T) {
if got := ParseCard(tt.card); got != tt.want {
t.Errorf("ParseCard(%s) = %d, want %d", tt.card, got, tt.want)
}
})
}
}

func TestBlackjack_Separate(t *testing.T) {
someAssignment := "test"
fmt.Println(someAssignment)

_ = "literally anything"

for _, tt := range testcases2 {
t.Run(tt.name, func(t *testing.T) {
got := IsBlackjack(tt.hand.card1, tt.hand.card2)
if got != tt.want {
t.Errorf("IsBlackjack(%s, %s) = %t, want %t", tt.hand.card1, tt.hand.card2, got, tt.want)
}
})
}

// Additional statements should be included
fmt.Println("the whole block")
fmt.Println("should be returned")
}
func TestSubtest_MultiAssignStmt(t *testing.T) {
someAssignment := "test"

myTests := []struct {
name string
card string
want int
}{
{
name: "parse two",
card: "two",
want: 2,
},
{
name: "parse jack",
card: "jack",
want: 10,
},
{
name: "parse king",
card: "king",
want: 10,
},
}

someAssignment2 := "test2"

for _, tt := range myTests {
t.Run(tt.name, func(t *testing.T) {
if got := ParseCard(tt.card); got != tt.want {
t.Errorf("ParseCard(%s) = %d, want %d", tt.card, got, tt.want)
}
})
}

// Additional statements should be included
fmt.Println("the whole block")
fmt.Println("should be returned")
}
72 changes: 72 additions & 0 deletions testrunner/testdata/expected/separate_cases_file.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"status": "pass",
"version": 3,
"tests": [
{
"name": "TestParseCard Separate/ parse two",
"status": "pass",
"test_code": "func TestParseCard_Separate(t *testing.T) {\n\ttt := struct {\n\t\tname string\n\t\tcard string\n\t\twant int\n\t}{\n\t\tname: \"parse two\",\n\t\tcard: \"two\",\n\t\twant: 2,\n\t}\n\n\tif got := ParseCard(tt.card); got != tt.want {\n\t\tt.Errorf(\"ParseCard(%s) = %d, want %d\", tt.card, got, tt.want)\n\t}\n\n}",
"message": "\n=== RUN TestParseCard_Separate/parse_two\n\n--- PASS: TestParseCard_Separate/parse_two \n"
},
{
"name": "TestParseCard Separate/ parse jack",
"status": "pass",
"test_code": "func TestParseCard_Separate(t *testing.T) {\n\ttt := struct {\n\t\tname string\n\t\tcard string\n\t\twant int\n\t}{\n\t\tname: \"parse jack\",\n\t\tcard: \"jack\",\n\t\twant: 10,\n\t}\n\n\tif got := ParseCard(tt.card); got != tt.want {\n\t\tt.Errorf(\"ParseCard(%s) = %d, want %d\", tt.card, got, tt.want)\n\t}\n\n}",
"message": "\n=== RUN TestParseCard_Separate/parse_jack\n\n--- PASS: TestParseCard_Separate/parse_jack \n"
},
{
"name": "TestParseCard Separate/ parse king",
"status": "pass",
"test_code": "func TestParseCard_Separate(t *testing.T) {\n\ttt := struct {\n\t\tname string\n\t\tcard string\n\t\twant int\n\t}{\n\t\tname: \"parse king\",\n\t\tcard: \"king\",\n\t\twant: 10,\n\t}\n\n\tif got := ParseCard(tt.card); got != tt.want {\n\t\tt.Errorf(\"ParseCard(%s) = %d, want %d\", tt.card, got, tt.want)\n\t}\n\n}",
"message": "\n=== RUN TestParseCard_Separate/parse_king\n\n--- PASS: TestParseCard_Separate/parse_king \n"
},
{
"name": "TestBlackjack Separate/ blackjack with ten (ace first)",
"status": "pass",
"test_code": "func TestBlackjack_Separate(t *testing.T) {\n\ttt := struct {\n\t\tname string\n\t\thand hand\n\t\twant bool\n\t}{\n\t\tname: \"blackjack with ten (ace first)\",\n\t\thand: hand{card1: \"ace\", card2: \"ten\"},\n\t\twant: true,\n\t}\n\tsomeAssignment := \"test\"\n\tfmt.Println(someAssignment)\n\n\t_ = \"literally anything\"\n\n\tgot := IsBlackjack(tt.hand.card1, tt.hand.card2)\n\tif got != tt.want {\n\t\tt.Errorf(\"IsBlackjack(%s, %s) = %t, want %t\", tt.hand.card1, tt.hand.card2, got, tt.want)\n\t}\n\n\t// Additional statements should be included\n\tfmt.Println(\"the whole block\")\n\tfmt.Println(\"should be returned\")\n}",
"message": "\n=== RUN TestBlackjack_Separate/blackjack_with_ten_(ace_first)\n\n--- PASS: TestBlackjack_Separate/blackjack_with_ten_(ace_first) \n"
},
{
"name": "TestBlackjack Separate/ blackjack with jack (ace first)",
"status": "pass",
"test_code": "func TestBlackjack_Separate(t *testing.T) {\n\ttt := struct {\n\t\tname string\n\t\thand hand\n\t\twant bool\n\t}{\n\t\tname: \"blackjack with jack (ace first)\",\n\t\thand: hand{card1: \"ace\", card2: \"jack\"},\n\t\twant: true,\n\t}\n\tsomeAssignment := \"test\"\n\tfmt.Println(someAssignment)\n\n\t_ = \"literally anything\"\n\n\tgot := IsBlackjack(tt.hand.card1, tt.hand.card2)\n\tif got != tt.want {\n\t\tt.Errorf(\"IsBlackjack(%s, %s) = %t, want %t\", tt.hand.card1, tt.hand.card2, got, tt.want)\n\t}\n\n\t// Additional statements should be included\n\tfmt.Println(\"the whole block\")\n\tfmt.Println(\"should be returned\")\n}",
"message": "\n=== RUN TestBlackjack_Separate/blackjack_with_jack_(ace_first)\n\n--- PASS: TestBlackjack_Separate/blackjack_with_jack_(ace_first) \n"
},
{
"name": "TestBlackjack Separate/ blackjack with queen (ace first)",
"status": "pass",
"test_code": "func TestBlackjack_Separate(t *testing.T) {\n\ttt := struct {\n\t\tname string\n\t\thand hand\n\t\twant bool\n\t}{\n\t\tname: \"blackjack with queen (ace first)\",\n\t\thand: hand{\n\t\t\tcard1: \"ace\", card2: \"queen\",\n\t\t},\n\t\twant: true,\n\t}\n\tsomeAssignment := \"test\"\n\tfmt.Println(someAssignment)\n\n\t_ = \"literally anything\"\n\n\tgot := IsBlackjack(tt.hand.card1, tt.hand.card2)\n\tif got != tt.want {\n\t\tt.Errorf(\"IsBlackjack(%s, %s) = %t, want %t\", tt.hand.card1, tt.hand.card2, got, tt.want)\n\t}\n\n\t// Additional statements should be included\n\tfmt.Println(\"the whole block\")\n\tfmt.Println(\"should be returned\")\n}",
"message": "\n=== RUN TestBlackjack_Separate/blackjack_with_queen_(ace_first)\n\n--- PASS: TestBlackjack_Separate/blackjack_with_queen_(ace_first) \n"
},
{
"name": "TestBlackjack Separate/ blackjack with king (ace first)",
"status": "pass",
"test_code": "func TestBlackjack_Separate(t *testing.T) {\n\ttt := struct {\n\t\tname string\n\t\thand hand\n\t\twant bool\n\t}{\n\t\tname: \"blackjack with king (ace first)\",\n\t\thand: hand{card1: \"ace\", card2: \"king\"},\n\t\twant: true,\n\t}\n\tsomeAssignment := \"test\"\n\tfmt.Println(someAssignment)\n\n\t_ = \"literally anything\"\n\n\tgot := IsBlackjack(tt.hand.card1, tt.hand.card2)\n\tif got != tt.want {\n\t\tt.Errorf(\"IsBlackjack(%s, %s) = %t, want %t\", tt.hand.card1, tt.hand.card2, got, tt.want)\n\t}\n\n\t// Additional statements should be included\n\tfmt.Println(\"the whole block\")\n\tfmt.Println(\"should be returned\")\n}",
"message": "\n=== RUN TestBlackjack_Separate/blackjack_with_king_(ace_first)\n\n--- PASS: TestBlackjack_Separate/blackjack_with_king_(ace_first) \n"
},
{
"name": "TestBlackjack Separate/ no blackjack with eight and five",
"status": "pass",
"test_code": "func TestBlackjack_Separate(t *testing.T) {\n\ttt := struct {\n\t\tname string\n\t\thand hand\n\t\twant bool\n\t}{\n\t\tname: \"no blackjack with eight and five\",\n\t\thand: hand{card2: \"eight\", card1: \"five\"},\n\t\twant: false,\n\t}\n\tsomeAssignment := \"test\"\n\tfmt.Println(someAssignment)\n\n\t_ = \"literally anything\"\n\n\tgot := IsBlackjack(tt.hand.card1, tt.hand.card2)\n\tif got != tt.want {\n\t\tt.Errorf(\"IsBlackjack(%s, %s) = %t, want %t\", tt.hand.card1, tt.hand.card2, got, tt.want)\n\t}\n\n\t// Additional statements should be included\n\tfmt.Println(\"the whole block\")\n\tfmt.Println(\"should be returned\")\n}",
"message": "\n=== RUN TestBlackjack_Separate/no_blackjack_with_eight_and_five\n\n--- PASS: TestBlackjack_Separate/no_blackjack_with_eight_and_five \n"
},
{
"name": "TestSubtest MultiAssignStmt/ parse two",
"status": "pass",
"test_code": "func TestSubtest_MultiAssignStmt(t *testing.T) {\n\tsomeAssignment := \"test\"\n\tfmt.Println(someAssignment)\n\n\ttt := struct {\n\t\tname string\n\t\tcard string\n\t\twant int\n\t}{\n\t\tname: \"parse two\",\n\t\tcard: \"two\",\n\t\twant: 2,\n\t}\n\n\tsomeAssignment2 := \"test2\"\n\tfmt.Println(someAssignment2)\n\n\tif got := ParseCard(tt.card); got != tt.want {\n\t\tt.Errorf(\"ParseCard(%s) = %d, want %d\", tt.card, got, tt.want)\n\t}\n\n\t// Additional statements should be included\n\tfmt.Println(\"the whole block\")\n\tfmt.Println(\"should be returned\")\n}",
"message": "\n=== RUN TestSubtest_MultiAssignStmt/parse_two\n\n--- PASS: TestSubtest_MultiAssignStmt/parse_two \n"
},
{
"name": "TestSubtest MultiAssignStmt/ parse jack",
"status": "pass",
"test_code": "func TestSubtest_MultiAssignStmt(t *testing.T) {\n\tsomeAssignment := \"test\"\n\tfmt.Println(someAssignment)\n\n\ttt := struct {\n\t\tname string\n\t\tcard string\n\t\twant int\n\t}{\n\t\tname: \"parse jack\",\n\t\tcard: \"jack\",\n\t\twant: 10,\n\t}\n\n\tsomeAssignment2 := \"test2\"\n\tfmt.Println(someAssignment2)\n\n\tif got := ParseCard(tt.card); got != tt.want {\n\t\tt.Errorf(\"ParseCard(%s) = %d, want %d\", tt.card, got, tt.want)\n\t}\n\n\t// Additional statements should be included\n\tfmt.Println(\"the whole block\")\n\tfmt.Println(\"should be returned\")\n}",
"message": "\n=== RUN TestSubtest_MultiAssignStmt/parse_jack\n\n--- PASS: TestSubtest_MultiAssignStmt/parse_jack \n"
},
{
"name": "TestSubtest MultiAssignStmt/ parse king",
"status": "pass",
"test_code": "func TestSubtest_MultiAssignStmt(t *testing.T) {\n\tsomeAssignment := \"test\"\n\tfmt.Println(someAssignment)\n\n\ttt := struct {\n\t\tname string\n\t\tcard string\n\t\twant int\n\t}{\n\t\tname: \"parse king\",\n\t\tcard: \"king\",\n\t\twant: 10,\n\t}\n\n\tsomeAssignment2 := \"test2\"\n\tfmt.Println(someAssignment2)\n\n\tif got := ParseCard(tt.card); got != tt.want {\n\t\tt.Errorf(\"ParseCard(%s) = %d, want %d\", tt.card, got, tt.want)\n\t}\n\n\t// Additional statements should be included\n\tfmt.Println(\"the whole block\")\n\tfmt.Println(\"should be returned\")\n}",
"message": "\n=== RUN TestSubtest_MultiAssignStmt/parse_king\n\n--- PASS: TestSubtest_MultiAssignStmt/parse_king \n"
}
]
}
23 changes: 23 additions & 0 deletions testrunner/testdata/practice/separate_cases_file/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"blurb": "...",
"authors": [
"..."
],
"contributors": [
"..."
],
"files": {
"solution": [
"conditionals.go"
],
"test": [
"conditionals_test.go"
],
"example": [
".meta/example.go"
]
},
"custom": {
"taskIdsEnabled": false
}
}

0 comments on commit 96e2c00

Please sign in to comment.