"""
<Description>
  Tests if the congestion controller's update
  function works.

<Date>
  February 26, 2009
"""
include congestion_controller.repy


def test_incr_slow_start():
  contr = CongestionController()
  contr.incr()
  assert contr.window_size == CONG_WINDOW_SIZE * 2
  assert contr.threshold == None

def test_incr_avoidance():
  contr = CongestionController()
  contr.window_size = 5 * CONG_WINDOW_SIZE
  contr.threshold = 5 * CONG_WINDOW_SIZE
  contr.increment = (1.0 / 5.0) * CONG_WINDOW_SIZE
  contr.incr()
  assert contr.window_size == (5 * CONG_WINDOW_SIZE) + (1.0 / 5.0) * CONG_WINDOW_SIZE
  contr.incr()
  assert contr.window_size == (5 * CONG_WINDOW_SIZE) + (2.0 / 5.0) * CONG_WINDOW_SIZE
  contr.incr()
  contr.incr()
  contr.incr()
  assert contr.window_size == (6 * CONG_WINDOW_SIZE)

  assert contr.threshold == 5 * CONG_WINDOW_SIZE
  assert contr.increment == (1.0 / 5.0) * CONG_WINDOW_SIZE

def main():
  # setup

  # Tests  
  test_incr_slow_start()
  test_incr_avoidance()

  # teardown
  exitall()


if callfunc == 'initialize':
  main()
