diff options
author | Julien Dessaux | 2021-09-19 01:14:58 +0200 |
---|---|---|
committer | Julien Dessaux | 2021-09-19 01:14:58 +0200 |
commit | e8662451d43c8c1f33ab4b921f9fa442ce4f0ead (patch) | |
tree | 8ac8201578380d7262a7fa82d197cc45d8244071 /pkg/field/utils_test.go | |
parent | Moved isIn function to a util file (diff) | |
download | gofunge98-e8662451d43c8c1f33ab4b921f9fa442ce4f0ead.tar.gz gofunge98-e8662451d43c8c1f33ab4b921f9fa442ce4f0ead.tar.bz2 gofunge98-e8662451d43c8c1f33ab4b921f9fa442ce4f0ead.zip |
Implemented function to get a field value
Diffstat (limited to 'pkg/field/utils_test.go')
-rw-r--r-- | pkg/field/utils_test.go | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/pkg/field/utils_test.go b/pkg/field/utils_test.go index bcc8deb..89b4d39 100644 --- a/pkg/field/utils_test.go +++ b/pkg/field/utils_test.go @@ -7,6 +7,39 @@ import ( "github.com/stretchr/testify/require" ) +func TestGet(t *testing.T) { + // Test cases + testCases := []struct { + name string + input string + inputX int + inputY int + expected int + }{ + {"minimal0,0", "test_data/minimal.b98", 0, 0, '@'}, + {"minimal-1,0", "test_data/minimal.b98", -1, 0, ' '}, + {"minimal1,0", "test_data/minimal.b98", 1, 0, ' '}, + {"minimal0,-1", "test_data/minimal.b98", 0, -1, ' '}, + {"minimal0,1", "test_data/minimal.b98", 0, 1, ' '}, + {"hello3,0", "test_data/hello.b98", 3, 0, '"'}, + {"hello3,1", "test_data/hello.b98", 3, 1, ' '}, + {"factorial0,1", "test_data/factorial.b98", 0, 1, ' '}, + {"factorial14,1", "test_data/factorial.b98", 14, 1, ' '}, + {"factorial15,1", "test_data/factorial.b98", 15, 1, ' '}, + } + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + file, err := os.Open(tc.input) + require.NoError(t, err, "Failed to open file") + defer file.Close() + field, err := LoadFile(file) + valid := field.Get(tc.inputX, tc.inputY) + require.NoError(t, err) + require.Equal(t, tc.expected, valid, "Invalid value") + }) + } +} + func TestIsIn(t *testing.T) { // Test cases testCases := []struct { |