forked from RedHatOfficial/GoCourse
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package accumulator | ||
|
||
type acc struct { | ||
value int | ||
} | ||
|
||
func (a *acc) accumulate(x int) { | ||
a.value += x | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package accumulator | ||
|
||
import ( | ||
"fmt" | ||
"github.com/DATA-DOG/godog" | ||
) | ||
|
||
var testAccumulator *acc | ||
|
||
func iHaveAnAccumulatorWith(initialValue int) error { | ||
testAccumulator.value = initialValue | ||
return nil | ||
} | ||
|
||
func iAddToAccumulator(value int) error { | ||
testAccumulator.accumulate(value) | ||
return nil | ||
} | ||
|
||
func theAccumulatedResultShouldBe(expected int) error { | ||
if testAccumulator.value == expected { | ||
return nil | ||
} | ||
return fmt.Errorf("Incorrect accumulator value") | ||
} | ||
|
||
func FeatureContext(s *godog.Suite) { | ||
s.Step(`^I have an accumulator with (-?\d+)$`, iHaveAnAccumulatorWith) | ||
s.Step(`^I add (-?\d+) to accumulator$`, iAddToAccumulator) | ||
s.Step(`^the accumulated result should be (-?\d+)$`, theAccumulatedResultShouldBe) | ||
|
||
s.BeforeScenario(func(interface{}) { | ||
testAccumulator = &acc{} | ||
}) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Feature: simple accumulator checks | ||
An accumulator must be able to add a number to its content | ||
|
||
Scenario: Accumulate positive integer | ||
Given I have an accumulator with 0 | ||
When I add 2 to accumulator | ||
Then the accumulated result should be 2 | ||
|
||
Scenario: Accumulate negative integer | ||
Given I have an accumulator with 0 | ||
When I add -2 to accumulator | ||
Then the accumulated result should be -2 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
You can implement step definitions for undefined steps with these snippets: | ||
|
||
func iAddToAccumulator(arg1 int) error { | ||
return godog.ErrPending | ||
} | ||
|
||
func theAccumulatedResultShouldBe(arg1 int) error { | ||
return godog.ErrPending | ||
} | ||
|
||
func FeatureContext(s *godog.Suite) { | ||
s.Step(`^I add -(\d+) to accumulator$`, iAddToAccumulator) | ||
s.Step(`^the accumulated result should be -(\d+)$`, theAccumulatedResultShouldBe) | ||
} |