// vim: syntax=cpp /* * Copyright (C) 2007-2010 Xagasoft, All rights reserved. * * This file is part of the libbu++ library and is released under the * terms of the license contained in the file LICENSE. */ #include "bu/fstring.h" #include "bu/list.h" typedef Bu::List IntList; {=Init} {%append} { IntList lst; for( int j = 0; j < 50; j++ ) { lst.append( j ); } int j = 0; for( IntList::iterator i = lst.begin(); i; i++, j++ ) { unitTest( *i == j ); } } {%prepend} { IntList lst; for( int j = 0; j < 50; j++ ) { lst.prepend( j ); } int j = 49; for( IntList::iterator i = lst.begin(); i; i++, j-- ) { unitTest( *i == j ); } } {%copy} { IntList lst; int j; for( j = 0; j < 50; j++ ) { lst.append( j ); } IntList lst2 = lst; j = 0; for( IntList::iterator i = lst2.begin(); i; i++, j++ ) { unitTest( *i == j ); } lst2.clear(); lst2 = lst; j = 0; for( IntList::iterator i = lst2.begin(); i; i++, j++ ) { unitTest( *i == j ); } } {%sort1} { IntList lst; lst.insertSorted( 5 ); lst.insertSorted( 1 ); lst.insertSorted( 10 ); lst.insertSorted( 3 ); unitTest( lst == IntList(1).append(3).append(5).append(10) ); } {%sort2} { IntList lst; lst.insertSorted >( 5 ); lst.insertSorted >( 1 ); lst.insertSorted >( 10 ); lst.insertSorted >( 3 ); unitTest( lst == IntList(10).append(5).append(3).append(1) ); } {%sort3} { IntList lst; Bu::__basicGTCmp cmp; lst.insertSorted( cmp, 5 ); lst.insertSorted( cmp, 1 ); lst.insertSorted( cmp, 10 ); lst.insertSorted( cmp, 3 ); unitTest( lst == IntList(10).append(5).append(3).append(1) ); } {%sort4} { IntList lst; lst.append( 5 ); lst.append( 1 ); lst.append( 10 ); lst.append( 3 ); lst.sort(); unitTest( lst == IntList(1).append(3).append(5).append(10) ); } {%sort5} { IntList lst; lst.append( 5 ); lst.append( 1 ); lst.append( 10 ); lst.append( 3 ); lst.sort >(); unitTest( lst == IntList(10).append(5).append(3).append(1) ); } {%sort6} { IntList lst; lst.append( 5 ); lst.append( 1 ); lst.append( 10 ); lst.append( 3 ); Bu::__basicGTCmp x; lst.sort( x ); unitTest( lst == IntList(10).append(5).append(3).append(1) ); }