Created
June 12, 2019 03:21
-
-
Save ridhoperdana/5d277ccacd0633d566e0778feebec91d to your computer and use it in GitHub Desktop.
Testfile for operation.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package calculator_test | |
| import ( | |
| "context" | |
| "testing" | |
| "github.com/ridhoperdana/calculator" | |
| ) | |
| func TestSempoa_Add(t *testing.T) { | |
| t.Run("success add number", func(t *testing.T) { | |
| s := calculator.InitOperation() | |
| result, err := s.Add(context.TODO(), 5) | |
| if err != nil { | |
| t.Fail() | |
| } | |
| if result != 5 { | |
| t.Fail() | |
| } | |
| if s.SavedNumber != 5 { | |
| t.Fail() | |
| } | |
| }) | |
| t.Run("success add negative number", func(t *testing.T) { | |
| s := calculator.InitOperation() | |
| result, err := s.Add(context.TODO(), -5) | |
| if err != nil { | |
| t.Fail() | |
| } | |
| if result != -5 { | |
| t.Fail() | |
| } | |
| if s.SavedNumber != -5 { | |
| t.Fail() | |
| } | |
| }) | |
| t.Run("success add more than one number", func(t *testing.T) { | |
| s := calculator.InitOperation() | |
| result, err := s.Add(context.TODO(), -5) | |
| if err != nil { | |
| t.Fail() | |
| } | |
| if result != -5 { | |
| t.Fail() | |
| } | |
| result, err = s.Add(context.TODO(), 10) | |
| if err != nil { | |
| t.Fail() | |
| } | |
| if result != 5 { | |
| t.Fail() | |
| } | |
| }) | |
| } | |
| func TestSempoa_Minus(t *testing.T) { | |
| t.Run("success minus number", func(t *testing.T) { | |
| s := calculator.InitOperation() | |
| result, err := s.Minus(context.TODO(), 5) | |
| if err != nil { | |
| t.Fail() | |
| } | |
| if result != -5 { | |
| t.Fail() | |
| } | |
| if s.SavedNumber != -5 { | |
| t.Fail() | |
| } | |
| }) | |
| t.Run("success minus negative number", func(t *testing.T) { | |
| s := calculator.InitOperation() | |
| result, err := s.Minus(context.TODO(), -5) | |
| if err != nil { | |
| t.Fail() | |
| } | |
| if result != 5 { | |
| t.Fail() | |
| } | |
| if s.SavedNumber != 5 { | |
| t.Fail() | |
| } | |
| }) | |
| t.Run("success minus more than one number", func(t *testing.T) { | |
| s := calculator.InitOperation() | |
| result, err := s.Minus(context.TODO(), -5) | |
| if err != nil { | |
| t.Fail() | |
| } | |
| if result != 5 { | |
| t.Fail() | |
| } | |
| result, err = s.Minus(context.TODO(), 10) | |
| if err != nil { | |
| t.Fail() | |
| } | |
| if result != -5 { | |
| t.Fail() | |
| } | |
| }) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment