Skip to content

Instantly share code, notes, and snippets.

@nisanthchunduru
Last active August 29, 2015 14:18
Show Gist options
  • Save nisanthchunduru/5f3a13260e036755b37a to your computer and use it in GitHub Desktop.
Save nisanthchunduru/5f3a13260e036755b37a to your computer and use it in GitHub Desktop.
TDD Demo BITS Goa
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()
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