package common import ( "testing" ) func TestFIFO(t *testing.T) { fifo := NewFifo(5) if fifo.MaxLen() != 5 { t.Fatal("unexpected fifo max_len:", fifo.MaxLen()) } if fifo.Len() != 0 { t.Fatal("unexpected fifo len:", fifo.Len()) } fifo.Push(1) fifo.Push(2) fifo.Push(3) fifo.Push(4) fifo.Push(5) fifo.Push(6) t.Log("fifo:", fifo.List()) if fifo.Len() != 5 { t.Fatal("unexpected fifo len:", fifo.Len()) } if fifo.Front().Value.(int) != 2 { t.Fatalf("unexpected front:%v", fifo.Front().Value.(int)) } if fifo.Back().Value.(int) != 6 { t.Fatalf("unexpected back:%v", fifo.Back().Value.(int)) } pop := fifo.Pop().(int) if pop != 2 { t.Fatalf("unexpected pop:%v", pop) } fifo.Pop() fifo.Pop() fifo.Pop() fifo.Pop() if fifo.Len() != 0 { t.Fatal("unexpected fifo len:", fifo.Len()) } if fifo.Pop() != nil { t.Fatal("fifo pop empty should return nil") } }