package main import ( "testing" ) func TestParseString(t *testing.T) { input := "00.23" fs := parseString(input) if ret := fs.String(); ret != input { t.Errorf("Expected %s received %s", input, ret) } } func TestDefragmentize1(t *testing.T) { fs := parseString("00..11") fs.OptimizeDiskFragmentation() expt := "0011.." if ret := fs.String(); ret != expt { t.Errorf("Expected %s received %s", expt, ret) } } func TestDefragmentize2(t *testing.T) { fs := parseString("00.112") fs.OptimizeDiskFragmentation() expt := "00211." if ret := fs.String(); ret != expt { t.Errorf("Expected %s received %s", expt, ret) } } func TestDefragmentize3(t *testing.T) { fs := parseString("00...112.") fs.OptimizeDiskFragmentation() expt := "00211...." if ret := fs.String(); ret != expt { t.Errorf("Expected %s received %s", expt, ret) } } func TestDefragmentize4(t *testing.T) { fs := parseString("00...111...2...333.44.5555.6666.777.888899") fs.OptimizeDiskFragmentation() expt := "0099811188827773336446555566.............." if ret := fs.String(); ret != expt { t.Errorf("Expected %s received %s", expt, ret) } } func TestFilterInPlace(t *testing.T) { dll := NewDLL[int]() dll.InsertFirst(4) dll.InsertFirst(3) dll.InsertFirst(2) dll.InsertFirst(1) dll.FilterInPlace(func(x int) bool { return x%2 == 0 }) } func TestGroupByInPlace(t *testing.T) { dll := NewDLL[int]() dll.InsertFirst(4) dll.InsertFirst(6) dll.InsertFirst(3) dll.InsertFirst(5) dll.InsertFirst(2) dll.GroupByInPlace(func(x, y int) (int, bool) { if x%2 != y%2 { return 0, false } return x + y, true }) }