Skip to content

Commit e093153

Browse files
committed
PR Comments Review
1 parent 67ec076 commit e093153

File tree

2 files changed

+83
-47
lines changed

2 files changed

+83
-47
lines changed

commands/showcases.go

+47-39
Original file line numberDiff line numberDiff line change
@@ -9,49 +9,60 @@ import (
99
"path"
1010
)
1111

12-
// print test cases table
13-
func PrintTestCasesTable(inputFiles, outputFiles map[string]config.IoFile) {
14-
t := table.NewWriter()
15-
t.SetOutputMirror(os.Stdout)
16-
t.AppendHeader(table.Row{"#", "Test Name", "Input Path", "Output Path", "Custon"})
17-
for key, inputFile := range inputFiles {
18-
id := inputFile.GetId()
19-
testName := inputFile.Name
20-
inputPath := inputFile.Path
21-
outputPath := ""
22-
custom := inputFile.Custom
12+
type TestCaseIO struct {
13+
Id int
14+
Name string
15+
InputPath string
16+
OutputPath string
17+
Custom bool
18+
}
2319

24-
outputFile, ok := outputFiles[key]
25-
if ok {
26-
outputPath = outputFile.Path
20+
// parse input and output from egor meta to TestCase
21+
func GetTestCases(egorMeta config.EgorMeta) []*TestCaseIO {
22+
testCasesMap := make(map[string]*TestCaseIO)
23+
testCases := make([]*TestCaseIO, 0)
24+
for _, input := range egorMeta.Inputs {
25+
testCase := &TestCaseIO {
26+
Id : input.GetId(),
27+
Name : input.Name,
28+
InputPath : input.Path,
29+
OutputPath: "",
30+
Custom: input.Custom,
2731
}
28-
29-
t.AppendRow([]interface{}{id, testName, inputPath, outputPath, custom})
32+
testCasesMap[input.Name] = testCase
33+
testCases = append(testCases, testCase)
3034
}
31-
t.SetStyle(table.StyleLight)
32-
t.Render()
33-
}
3435

35-
// construct inputs and outputs maps from an egor meta data where keys are test names.
36-
func GetIoFilesMaps(egorMeta config.EgorMeta) (map[string]config.IoFile, map[string]config.IoFile) {
37-
inputFiles := make(map[string]config.IoFile)
38-
for _, inputFile := range egorMeta.Inputs {
39-
inputFiles[inputFile.Name] = inputFile
36+
for _, output := range egorMeta.Outputs {
37+
if testCase, ok := testCasesMap[output.Name]; ok {
38+
testCase.OutputPath = output.Path
39+
}
4040
}
4141

42-
outputFiles := make(map[string]config.IoFile)
43-
for _, outputFile := range egorMeta.Outputs {
44-
outputFiles[outputFile.Name] = outputFile
45-
}
42+
return testCases
43+
}
4644

47-
return inputFiles, outputFiles
45+
// print test cases table
46+
func PrintTestCasesTable(testCases []*TestCaseIO) {
47+
t := table.NewWriter()
48+
t.SetOutputMirror(os.Stdout)
49+
t.AppendHeader(table.Row{"#", "Test Name", "Input Path", "Output Path", "Custon"})
50+
for _, testCase := range testCases {
51+
t.AppendRow([]interface{}{
52+
testCase.Id,
53+
testCase.Name,
54+
testCase.InputPath,
55+
testCase.OutputPath,
56+
testCase.Custom,
57+
})
58+
}
59+
t.SetStyle(table.StyleLight)
60+
t.Render()
4861
}
4962

5063
// print task test cases
51-
func PrintTestCases(egorMeta config.EgorMeta) error {
52-
inputFiles, outputFiles := GetIoFilesMaps(egorMeta)
53-
PrintTestCasesTable(inputFiles, outputFiles)
54-
return nil
64+
func PrintTestCases(egorMeta config.EgorMeta) {
65+
PrintTestCasesTable(GetTestCases(egorMeta))
5566
}
5667

5768
// list test cases information command action
@@ -79,11 +90,8 @@ func ShowCasesAction(context *cli.Context) error {
7990
color.Green("Listing %d testcase(s)...", metaData.CountTestCases())
8091
color.Green("")
8192

82-
err = PrintTestCases(metaData)
83-
if err != nil {
84-
color.Red("Error while printing test cases")
85-
return err
86-
}
93+
PrintTestCases(metaData)
94+
8795
return nil
8896
}
8997

@@ -92,7 +100,7 @@ func ShowCasesAction(context *cli.Context) error {
92100
// and prints it as an array into the consol.
93101
var ShowCasesCommand = cli.Command{
94102
Name: "showcases",
95-
Aliases: []string{"listcases"},
103+
Aliases: []string{"sc"},
96104
Usage: "list information about test cases",
97105
UsageText: "list meta data about of the tests cases in the current task",
98106
Action: ShowCasesAction,

commands/showcases_test.go

+36-8
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,45 @@
11
package commands
22

33
import (
4+
"github.com/chermehdi/egor/config"
45
"github.com/stretchr/testify/assert"
56
"testing"
67
)
78

8-
func TestGetIoFilesMaps(t *testing.T) {
9-
metaData := createDummyMetaData()
10-
inputs, outputs := GetIoFilesMaps(metaData)
9+
func createSimpleDummyMetaData() config.EgorMeta{
10+
meteData := config.EgorMeta {
11+
TaskName: "Dummy Task",
12+
TaskLang: "cpp",
13+
Inputs: []config.IoFile {
14+
config.IoFile {
15+
Name: "test-0",
16+
Path: "inputs/test-0.in",
17+
Custom: true,
18+
},
19+
},
20+
Outputs: []config.IoFile {
21+
config.IoFile {
22+
Name: "test-0",
23+
Path: "outputs/test-0.ans",
24+
Custom: true,
25+
},
26+
},
27+
}
1128

12-
assert.Equal(t, len(inputs), len(metaData.Inputs))
13-
assert.Equal(t, len(outputs), len(metaData.Outputs))
14-
assert.Equal(t, inputs["test-0"], metaData.Inputs[0])
15-
assert.Equal(t, inputs["test-1"], metaData.Inputs[1])
16-
assert.Equal(t, outputs["test-0"], metaData.Outputs[0])
29+
return meteData
1730
}
31+
32+
func TestGetTestCases(t *testing.T) {
33+
metaData := createDummyMetaData()
34+
testCases := GetTestCases(metaData)
35+
inputs := metaData.Inputs
36+
outputs := metaData.Outputs
37+
38+
assert.Equal(t, len(testCases), len(metaData.Inputs))
39+
assert.Equal(t, testCases[0].Id, inputs[0].GetId())
40+
assert.Equal(t, testCases[0].Name, inputs[0].Name)
41+
assert.Equal(t, testCases[0].Name, outputs[0].Name)
42+
assert.Equal(t, testCases[0].InputPath, inputs[0].Path)
43+
assert.Equal(t, testCases[0].OutputPath, outputs[0].Path)
44+
assert.Equal(t, testCases[0].Custom, inputs[0].Custom)
45+
}

0 commit comments

Comments
 (0)