Last active
August 29, 2015 14:18
-
-
Save nisanthchunduru/5f3a13260e036755b37a to your computer and use it in GitHub Desktop.
TDD Demo BITS Goa
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
require 'ansi' | |
def puts_red(text) | |
puts ANSI.red { text } | |
end | |
def puts_green(text) | |
puts ANSI.green { text } | |
end | |
def stack_create | |
[] | |
end | |
def stack_push(stack, item) | |
stack << item | |
end | |
def stack_pop(stack) | |
stack.pop | |
end | |
# Tests | |
def test_stack_push | |
stack = stack_create() | |
stack_push(stack, 5) | |
puts_green "push to stack" | |
end | |
test_stack_push(); | |
def test_empty_stack_pop | |
stack = stack_create() | |
item = stack_pop(stack) | |
if item != nil | |
puts_red "Item isn't nil!" | |
exit | |
end | |
puts_green "pop from empty stack" | |
end | |
test_empty_stack_pop() | |
def test_stack_pop | |
stack = stack_create() | |
stack_push(stack, 1) | |
item = stack_pop(stack) | |
if item != 1 | |
puts_red "Item isn't 1!" | |
exit | |
end | |
puts_green "pop from stack" | |
end | |
test_stack_pop() | |
def test_multiple_stack_pop | |
stack = stack_create() | |
stack_push(stack, 1) | |
stack_push(stack, 2) | |
item = stack_pop(stack) | |
if item != 2 | |
puts_red "Item isn't 2" | |
exit | |
end | |
item = stack_pop(stack) | |
if item != 1 | |
puts_red "Item isn't 2" | |
exit | |
end | |
puts_green "pop multiple items from stack" | |
end | |
test_multiple_stack_pop() |
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
Here's a browser runnable example http://runnable.com/VSJcr_cptp4RLxht/tdd-demo-bits-goa-for-ruby |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment