From 9a6be93575b2da2c6dff230b258eb1f743e9c0f6 Mon Sep 17 00:00:00 2001 From: cheatsnake <72691412+cheatsnake@users.noreply.github.com> Date: Sun, 29 Jan 2023 11:31:09 +0300 Subject: [PATCH] refactor: Change isError to isValid --- pkg/camp/core_test.go | 8 ++++---- pkg/camp/types.go | 2 +- pkg/sudoku/core_test.go | 6 +++--- pkg/sudoku/types.go | 2 +- pkg/sudoku/verification.go | 8 ++++---- pkg/takuzu/core_test.go | 14 +++----------- pkg/takuzu/types.go | 2 +- pkg/takuzu/verification.go | 8 ++++---- 8 files changed, 21 insertions(+), 29 deletions(-) diff --git a/pkg/camp/core_test.go b/pkg/camp/core_test.go index 3655ae1..db250a4 100644 --- a/pkg/camp/core_test.go +++ b/pkg/camp/core_test.go @@ -40,8 +40,8 @@ func TestVerify(t *testing.T) { testValidValue := verifyArgs{[]int{1, 1, 1, 1, 1}, []int{1, 1, 0, 3, 0}, [][]int{{1, 0, 0, 2, 0}, {2, 0, 0, 1, 0}, {0, 0, 0, 2, 1}, {0, 2, 0, 0, 0}, {0, 1, 0, 2, 1}}} result, err := Verify(testValidValue.Solution, testValidValue.RowTents, testValidValue.ColumnTents) - if err != nil || result.IsError { - t.Errorf("Verify(...) with valid args FAILED. Expected error != nil & result.IsError = false, but got %v, %v", err, result.IsError) + if err != nil || result.IsValid { + t.Errorf("Verify(...) with valid args FAILED. Expected error != nil & result.IsValid = false, but got %v, %v", err, result.IsValid) } else { t.Logf("Verify(...) PASSED") } @@ -50,8 +50,8 @@ func TestVerify(t *testing.T) { result, err = Verify(testInvalidValue.Solution, testInvalidValue.RowTents, testInvalidValue.ColumnTents) - if err != nil || !result.IsError { - t.Errorf("Verify(...) with invalid args FAILED. Expected error = nil & result.IsError = true, but got %v, %v", err, result.IsError) + if err != nil || !result.IsValid { + t.Errorf("Verify(...) with invalid args FAILED. Expected error = nil & result.IsValid = true, but got %v, %v", err, result.IsValid) } else { t.Logf("Verify(...) PASSED") } diff --git a/pkg/camp/types.go b/pkg/camp/types.go index 626c172..04f2fb7 100644 --- a/pkg/camp/types.go +++ b/pkg/camp/types.go @@ -11,7 +11,7 @@ type Core struct { } type VerifyResult struct { - IsError bool `json:"isError"` + IsValid bool `json:"isValid"` Position string `json:"position"` Message string `json:"message"` } diff --git a/pkg/sudoku/core_test.go b/pkg/sudoku/core_test.go index d734b07..f3a310d 100644 --- a/pkg/sudoku/core_test.go +++ b/pkg/sudoku/core_test.go @@ -108,7 +108,7 @@ func TestVerify(t *testing.T) { // check 100% filled task result := testCore.Verify() - if result.IsError { + if !result.IsValid { t.Errorf("testCore.Verify() FAILED. Should be verified, but got error at position %+v", result.Position) } else { t.Logf("testCore.Verify() PASSED") @@ -119,7 +119,7 @@ func TestVerify(t *testing.T) { testCore.Task[0][1] = 1 result = testCore.Verify() - if !result.IsError { + if result.IsValid { t.Errorf("testCore.Verify() FAILED. Should be an error, but got verified") } else { t.Logf("testCore.Verify() PASSED") @@ -130,7 +130,7 @@ func TestVerify(t *testing.T) { testCore.Task[1][0] = 1 result = testCore.Verify() - if !result.IsError { + if result.IsValid { t.Errorf("testCore.Verify() FAILED. Should be an error, but got verified") } else { t.Logf("testCore.Verify() PASSED") diff --git a/pkg/sudoku/types.go b/pkg/sudoku/types.go index cd55f6c..388d118 100644 --- a/pkg/sudoku/types.go +++ b/pkg/sudoku/types.go @@ -6,6 +6,6 @@ type Core struct { } type VerificationResult struct { - IsError bool `json:"isError"` + IsValid bool `json:"isValid"` Position string `json:"position"` } diff --git a/pkg/sudoku/verification.go b/pkg/sudoku/verification.go index 0350472..ec08ab4 100644 --- a/pkg/sudoku/verification.go +++ b/pkg/sudoku/verification.go @@ -8,12 +8,12 @@ import ( func verify(grid [9][9]int) *VerificationResult { verifyRows := checkRows(grid) - if verifyRows.IsError { + if !verifyRows.IsValid { return verifyRows } verifyColumns := checkColumns(grid) - if verifyColumns.IsError { + if !verifyColumns.IsValid { return verifyColumns } @@ -27,12 +27,12 @@ func сheckLines(grid [9][9]int, lineType string) *VerificationResult { for j := 1; j <= len(row); j++ { if j != row[j-1] { return &VerificationResult{ - true, lineType + "-" + strconv.Itoa(i+1), + false, lineType + "-" + strconv.Itoa(i+1), } } } } - return &VerificationResult{false, ""} + return &VerificationResult{true, ""} } func checkRows(grid [9][9]int) *VerificationResult { diff --git a/pkg/takuzu/core_test.go b/pkg/takuzu/core_test.go index 7e19d6d..0461bfc 100644 --- a/pkg/takuzu/core_test.go +++ b/pkg/takuzu/core_test.go @@ -88,17 +88,13 @@ func TestVerify(t *testing.T) { res, err := tc.Verify() if err == nil { t.Errorf("TestVerify FAILED. Should return error, but got %+v", res) - } else { - t.Logf("Verify() PASSED") } tc.Task = tc.Field res, _ = tc.Verify() - if res.IsError { + if !res.IsValid { t.Errorf("TestVerify FAILED. Should be verified, but got error: %+v", res) - } else { - t.Logf("Verify() PASSED") } tc.Task[0][0] = "1" @@ -106,10 +102,8 @@ func TestVerify(t *testing.T) { tc.Task[0][2] = "1" res, _ = tc.Verify() - if !res.IsError { + if res.IsValid { t.Errorf("TestVerify FAILED. Should be not verified, but verified: %+v", res) - } else { - t.Logf("Verify() PASSED") } tc.Generate() @@ -119,9 +113,7 @@ func TestVerify(t *testing.T) { tc.Task[2][0] = "1" res, _ = tc.Verify() - if !res.IsError { + if res.IsValid { t.Errorf("TestVerify FAILED. Should be not verified, but verified: %+v", res) - } else { - t.Logf("Verify() PASSED") } } diff --git a/pkg/takuzu/types.go b/pkg/takuzu/types.go index 6848f79..a076fda 100644 --- a/pkg/takuzu/types.go +++ b/pkg/takuzu/types.go @@ -7,7 +7,7 @@ type Core struct { } type VerificationResult struct { - IsError bool `json:"isError"` + IsValid bool `json:"isValid"` Message string `json:"message"` Position []string `json:"position"` } diff --git a/pkg/takuzu/verification.go b/pkg/takuzu/verification.go index d0dd00a..1874b11 100644 --- a/pkg/takuzu/verification.go +++ b/pkg/takuzu/verification.go @@ -28,13 +28,13 @@ func verify(field [][]string) (*VerificationResult, error) { result := checkLines(rows, "row") - if result.IsError { + if !result.IsValid { return result, errors.New(result.Message) } result = checkLines(columns, "column") - if result.IsError { + if !result.IsValid { return result, errors.New(result.Message) } @@ -62,7 +62,7 @@ func checkDuplication(lines []string, lineType string) []string { func defineVerificationError(msg string, pos []string) *VerificationResult { return &VerificationResult{ - IsError: true, + IsValid: false, Message: msg, Position: pos, } @@ -83,7 +83,7 @@ func checkBalance(line string) bool { func checkLines(lines []string, lineType string) *VerificationResult { result := &VerificationResult{ - IsError: false, + IsValid: true, Message: "", Position: []string{}, }