Skip to content

Commit

Permalink
BDD iteration RedHatOfficial#7
Browse files Browse the repository at this point in the history
  • Loading branch information
tisnik committed Nov 14, 2019
1 parent a36fa55 commit 4ef99f4
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
9 changes: 9 additions & 0 deletions testing/bdd_iteration_7/accumulator.go
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
}
35 changes: 35 additions & 0 deletions testing/bdd_iteration_7/accumulator_test.go
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{}
})
}
17 changes: 17 additions & 0 deletions testing/bdd_iteration_7/features/accumulator.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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>
When I add <amount2> to accumulator
Then the accumulated result should be <accumulated2>

Examples:
|amount|accumulated|amount2|accumulated2|
| 0 | 0 | 0 | 0 |
| 1 | 1 | 1 | 2 |
| 2 | 2 | 2 | 4 |
| 10 | 10 | 10 | 20 |

0 comments on commit 4ef99f4

Please sign in to comment.