Skip to content

Instantly share code, notes, and snippets.

@Vaguery
Created December 2, 2010 14:30
Show Gist options
  • Select an option

  • Save Vaguery/725402 to your computer and use it in GitHub Desktop.

Select an option

Save Vaguery/725402 to your computer and use it in GitHub Desktop.
Feature: Pile interpreter handles tokens as expected
In order to get consistent behavior when executing Pile scripts
As a symbolic regression modeler
I want each of the six basic token types to bring about expected changes in the Pile interpreter stack
Scenario: numerical constants are pushed onto the interpreter stack
Given the Pile script "-91.21"
When I execute it
Then there should be 1 item on the stack
And the top stack item should be -91.21
Scenario: only traditional floating-point numbers are recognized
Given the Pile script "-91.21e61.7"
When I execute it
Then the stack should be empty
And no errors should occur
Scenario: addition pushes the sum of 2 stack items
Given the Pile script "1.2 3.4 +"
When I execute it
Then there should be 1 item on the stack
And the top stack item should be 4.7
Scenario: subtraction pushes the difference of 2 stack items
Given the Pile script "1.2 3.4 -"
When I execute it
Then there should be 1 item on the stack
And the top stack item should be -2.2
Scenario: multiplication pushes the product of 2 stack items
Given the Pile script "1.2 3.4 *"
When I execute it
Then there should be 1 item on the stack
And the top stack item should be 4.08
Scenario: division pushes the quotient of 2 stack items
Given the Pile script "8.2 -2.0 /"
When I execute it
Then there should be 1 item on the stack
And the top stack item should be 4.1
Scenario: x pushes the bound value
Given the Pile script "x"
When I execute it with x = 2.1
Then there should be 1 item on the stack
And the top stack item should be 2.1
Scenario: instructions with missing arguments fail silently
Given the Pile script "9.1 *"
When I execute it
Then the top stack item should be 9.1
And there should be 1 item on the stack
And no errors should occur
Scenario: instructions with no arguments fail silently
Given the Pile script "+ / + *"
When I execute it
Then the stack should be empty
And no errors should occur
Scenario: division by zero ("protected division") results in 0.0
Given the Pile script "8.2 -0.0 /"
When I execute it
Then there should be 1 item on the stack
And the top stack item should be 0.0
And no errors should occur
Scenario: gibberish tokens fail silently
Given the Pile script "foo bar"
When I execute it
Then the stack should be empty
And no errors should occur
Scenario: empty scripts do nothing
Given the Pile script ""
When I execute it
Then the stack should be empty
And no errors should occur
Scenario: script execution leaves all resulting items on the stack
Given the Pile script "1.1 2.2 3.3 4.4 x"
When I execute it with x = 5.5
Then there should be 5 items on the stack
And the top stack item should be 5.5
And the bottom stack item should be 1.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment