nisanth074
4/6/2015 - 1:19 AM

TDD Demo BITS Goa

TDD Demo BITS Goa

Here's a browser runnable example http://runnable.com/VSJcr_cptp4RLxht/tdd-demo-bits-goa-for-ruby
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()