SRC_DIR = '../../src/log/'

StackList = (require SRC_DIR + 'StackList.coffee').StackList

list = new Object()

exports.setUp = (callback) ->
  list = new StackList 5
  list.push "key1", 1
  list.push "key2", 2
  list.push "key3", 3
  list.push "key4", 4
  callback()

exports.testPush = (test) ->
  test.expect 18
  test.equals list.length, 4
  test.equals list.get("key1"), 1
  test.equals list.get("key2"), 2
  test.equals list.get("key3"), 3
  test.equals list.get("key4"), 4
  test.equals list.get("key5"), undefined
  test.equals list.get("key6"), undefined
  test.equals list.bottomKey(), "key1"
  test.equals list.head.next.key, "key1"
  test.equals list.head.next.prev.key, undefined
  test.equals list.head.next.next.key, "key2"
  test.equals list.head.next.next.prev.key, "key1"
  test.equals list.head.next.next.next.key, "key3"
  test.equals list.head.next.next.next.prev.key, "key2"
  test.equals list.head.next.next.next.next.key, "key4"
  test.equals list.head.next.next.next.next.prev.key, "key3"
  test.equals list.head.next.next.next.next.next, undefined
  test.equals list.head.next.next.next.next, list.tail
  test.done()

exports.testRemove = (test) ->
  test.expect 15
  list.remove list.head.next
  test.equals list.length, 3
  test.equals list.get("key1"), undefined
  test.equals list.get("key2"), 2
  test.equals list.bottomKey(), "key2"
  test.equals list.head.next.key, "key2"
  test.equals list.head.next.next.key, "key3"
  test.equals list.head.next.next.next.key, "key4"
  test.equals list.head.next.next.next.next, undefined
  test.equals list.head.next.next.next, list.tail
  list.remove list.tail
  test.equals list.length, 2
  test.equals list.bottomKey(), "key2"
  test.equals list.head.next.key, "key2"
  test.equals list.head.next.next.key, "key3"
  test.equals list.head.next.next.next, undefined
  test.equals list.head.next.next, list.tail
  test.done()

exports.testMoveToTop = (test) ->
  test.expect 11
  list.remove list.head.next
  list.moveToTop "key2"
  test.equals list.length, 3
  test.equals list.get("key2"), 2
  test.equals list.get("key3"), 3
  test.equals list.get("key4"), 4
  test.equals list.get("key5"), undefined
  test.equals list.bottomKey(), "key3"
  test.equals list.head.next.key, "key3"
  test.equals list.head.next.next.key, "key4"
  test.equals list.head.next.next.next.key, "key2"
  test.equals list.head.next.next.next.next, undefined
  test.equals list.head.next.next.next, list.tail
  test.done()

exports.testPushManyNodes = (test) ->
  test.expect 15
  list.moveToTop "key2" # 1 3 4 2
  list.push "key5", 5
  list.push "key6", 6
  list.push "key7", 7 # 4 2 5 6 7
  test.equals list.length, 5
  test.equals list.get("key1"), undefined
  test.equals list.get("key2"), 2
  test.equals list.get("key3"), undefined
  test.equals list.get("key4"), 4
  test.equals list.get("key5"), 5
  test.equals list.get("key6"), 6
  test.equals list.get("key7"), 7
  test.equals list.bottomKey(), "key4"
  test.equals list.head.next.key, "key4"
  test.equals list.head.next.next.key, "key2"
  test.equals list.head.next.next.next.key, "key5"
  test.equals list.head.next.next.next.next.key, "key6"
  test.equals list.head.next.next.next.next.next.key, "key7"
  test.equals list.head.next.next.next.next.next.next, undefined
  test.done()



