1 import static org.junit.Assert.*; 2 import org.junit.Test; 3 4 public class TestArrayDequeGold { 5 @Test 6 public void testStudentArrayDeque() { 7 StudentArrayDeque<Integer> testArray = new StudentArrayDeque<>(); 8 ArrayDequeSolution<Integer> stdArray = new ArrayDequeSolution<>(); 9 String log = ""; 10 for (int i = 0; i < 1000; i++) { 11 if (stdArray.size() == 0) { 12 int addNumber = StdRandom.uniform(1000); 13 int headOrBack = StdRandom.uniform(2); 14 if (headOrBack == 0) { 15 log = log + "addFirst(" + addNumber + ")\n"; 16 testArray.addFirst(addNumber); 17 stdArray.addFirst(addNumber); 18 } else { 19 log = log + "addLast(" + addNumber + ")\n"; 20 testArray.addLast(addNumber); 21 stdArray.addLast(addNumber); 22 } 23 } else { 24 int x = StdRandom.uniform(4); 25 int addNumber = StdRandom.uniform(1000); 26 Integer testremoveNumber = 1; 27 Integer stdremoveNumber = 1; 28 switch (x) { 29 case 0: 30 log = log + "addFirst(" + addNumber + ")\n"; 31 testArray.addFirst(addNumber); 32 stdArray.addFirst(addNumber); 33 break; 34 case 1: 35 log = log + "addLast(" + addNumber + ")\n"; 36 testArray.addLast(addNumber); 37 stdArray.addLast(addNumber); 38 break; 39 case 2: 40 log = log + "removeFirst()\n"; 41 testremoveNumber = testArray.removeFirst(); 42 stdremoveNumber = stdArray.removeFirst(); 43 break; 44 case 3: 45 log = log + "removeLast()\n"; 46 testremoveNumber = testArray.removeLast(); 47 stdremoveNumber = stdArray.removeLast(); 48 break; 49 default: 50 } 51 assertEquals(log, stdremoveNumber, testremoveNumber); 52 } 53 } 54 55 } 56 }
标签:log,gold,testArray,CS61B,project,addLast,addFirst,stdArray,addNumber From: https://www.cnblogs.com/xuenima/p/17397581.html