Skip to content

Commit

Permalink
feat(tests): added new test cases loading tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Gurkengewuerz committed Oct 25, 2024
1 parent 41be7d7 commit 49ceede
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions internal/judge/testCases_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package judge_test

import (
"github.com/gurkengewuerz/GitCodeJudge/internal/judge"
"os"
"path/filepath"
"testing"
)

func TestLoadTestCases(t *testing.T) {
// Define the root directory containing task directories with config.yaml files
rootDir := "../../test_cases/"

// Walk through the root directory to find all config.yaml files
err := filepath.Walk(rootDir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}

// Check if the file is config.yaml
if info.Name() == "config.yaml" {
t.Run(path, func(t *testing.T) {
testCases, err := judge.LoadTestCases(filepath.Dir(path))
if err != nil {
t.Fatalf("Failed to load test cases from %s: %v", path, err)
}

// Perform some basic checks on the loaded test cases
if len(testCases) == 0 {
t.Errorf("No test cases loaded from %s", path)
}

for _, testCase := range testCases {
if testCase.Input == "" {
t.Errorf("Test case with empty input in %s", path)
}
if testCase.Expected == "" {
t.Errorf("Test case with empty expected output in %s", path)
}
}
})
}

return nil
})

cwd, cerr := os.Getwd()
if cerr != nil {
t.Fatalf("Failed to get cwd: %v", cerr)
}

if err != nil {
t.Fatalf("Failed to walk through root directory %s: %v", cwd, err)
}
}

0 comments on commit 49ceede

Please sign in to comment.