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
89 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 %d", testAccumulator.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,14 @@ | ||
Feature: simple accumulator checks | ||
An accumulator must be able to add a number to its content | ||
|
||
Scenario Outline: Accumulate multiple values | ||
Given I have an accumulator with 0 | ||
When I add <amount> to accumulator | ||
Then the accumulated result should be <accumulated> | ||
|
||
Examples: | ||
|amount|accumulated| | ||
| 0 | 0 | | ||
| 1 | 1 | | ||
| 1 | 2 | | ||
| 10 | 12 | |
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,31 @@ | ||
Feature: simple accumulator checks | ||
An accumulator must be able to add a number to its content | ||
|
||
Scenario Outline: Accumulate multiple values # features/accumulator.feature:4 | ||
Given I have an accumulator with 0 # accumulator_test.go:11 -> iHaveAnAccumulatorWith | ||
When I add <amount> to accumulator # accumulator_test.go:16 -> iAddToAccumulator | ||
Then the accumulated result should be <accumulated> # accumulator_test.go:20 -> theAccumulatedResultShouldBe | ||
|
||
Examples: | ||
| amount | accumulated | | ||
| 0 | 0 | | ||
| 1 | 1 | | ||
| 1 | 2 | | ||
Incorrect accumulator value 1 | ||
| 10 | 12 | | ||
Incorrect accumulator value 10 | ||
|
||
--- Failed steps: | ||
|
||
Scenario Outline: Accumulate multiple values # features/accumulator.feature:4 | ||
Then the accumulated result should be 2 # features/accumulator.feature:7 | ||
Error: Incorrect accumulator value 1 | ||
|
||
Scenario Outline: Accumulate multiple values # features/accumulator.feature:4 | ||
Then the accumulated result should be 12 # features/accumulator.feature:7 | ||
Error: Incorrect accumulator value 10 | ||
|
||
|
||
4 scenarios (2 passed, 2 failed) | ||
12 steps (10 passed, 2 failed) | ||
356.714µs |