├── README.md └── BarBrawlTest.java /README.md: -------------------------------------------------------------------------------- 1 | # rldm-hw7-tests 2 | -------------------------------------------------------------------------------- /BarBrawlTest.java: -------------------------------------------------------------------------------- 1 | import org.junit.Assert; 2 | import org.junit.Test; 3 | 4 | /** 5 | * Created by mimoralea on 10/3/15. 6 | */ 7 | public class BarBrawlTest { 8 | 9 | @Test 10 | public void test1() { 11 | int testCase = 1; 12 | int numOfPatrons = 2; 13 | int maxIDontKnows = 1; 14 | boolean[][] atEstablishment = { 15 | {true,true}, 16 | {true,false}, 17 | {false,true}, 18 | {true,true}, 19 | {false,false}, 20 | {true,false}, 21 | {true,true} 22 | }; 23 | boolean[] fightOccurred = { 24 | false, 25 | true, 26 | false, 27 | false, 28 | false, 29 | true, 30 | false 31 | }; 32 | this.generalTests(testCase, numOfPatrons, maxIDontKnows, atEstablishment, fightOccurred); 33 | } 34 | 35 | @Test 36 | public void test2() { 37 | int testCase = 2; 38 | int numOfPatrons = 3; 39 | int maxIDontKnows = 5; 40 | boolean[][] atEstablishment = { 41 | {true,true,true}, 42 | {true,true,false}, 43 | {true,false,true}, 44 | {false,true,true}, 45 | {true,false,false}, 46 | {false,true,false}, 47 | {false,false,true}, 48 | {false,false,false}, 49 | {true,false,true}, 50 | {false,true,true}, 51 | {true,false,false} 52 | }; 53 | boolean[] fightOccurred = { 54 | false, 55 | false, 56 | false, 57 | true, 58 | false, 59 | false, 60 | true, 61 | false, 62 | false, 63 | true, 64 | false 65 | }; 66 | this.generalTests(testCase, numOfPatrons, maxIDontKnows, atEstablishment, fightOccurred); 67 | } 68 | 69 | @Test 70 | public void test3() { 71 | int testCase = 3; 72 | int numOfPatrons = 5; 73 | int maxIDontKnows = 19; 74 | boolean[][] atEstablishment = { 75 | {false,false,true,true,false}, 76 | {true,true,false,false,false}, 77 | {true,false,true,false,false}, 78 | {false,true,true,false,false}, 79 | {true,false,true,false,false}, 80 | {false,false,false,true,true}, 81 | {false,true,false,true,false}, 82 | {true,false,false,true,false}, 83 | {true,false,false,false,true}, 84 | {false,true,false,false,true}, 85 | {false,false,true,false,true}, 86 | {true,false,true,false,true}, 87 | {true,true,true,false,true}, 88 | {false,true,false,false,false}, 89 | {true,true,true,true,true}, 90 | {true,false,false,false,false}, 91 | {false,false,false,true,true}, 92 | {true,true,false,true,true}, 93 | {false,false,false,true,false}, 94 | {true,true,true,true,false} 95 | }; 96 | boolean[] fightOccurred = { 97 | false, 98 | true, 99 | false, 100 | true, 101 | false, 102 | false, 103 | false, 104 | false, 105 | false, 106 | true, 107 | false, 108 | false, 109 | true, 110 | true, 111 | false, 112 | false, 113 | false, 114 | false, 115 | false, 116 | false 117 | }; 118 | this.generalTests(testCase, numOfPatrons, maxIDontKnows, atEstablishment, fightOccurred); 119 | } 120 | 121 | private void generalTests(int testCase, int numOfPatrons, int maxIDontKnows, boolean[][] atEstablishment, boolean[] fightOccurred) 122 | { 123 | System.out.println("Test case " + testCase); 124 | System.out.println("\n"); 125 | System.out.println("The parameter for the constructor of the BarBrawl object is:"); 126 | System.out.println("int numPatrons = " + numOfPatrons); 127 | System.out.println(); 128 | BarBrawl bb = new BarBrawl(numOfPatrons); 129 | 130 | String[] outputs = new String[atEstablishment.length]; 131 | int incorrectCounter = 0; 132 | int iDontKnowCounter = 0; 133 | for(int i = 0; i < atEstablishment.length; i++) 134 | { 135 | System.out.println("Calling predictOutcome with argument:"); 136 | System.out.print("boolean[] atEstablishment = {"); 137 | for(int j = 0; j < atEstablishment[i].length; j++) 138 | { 139 | System.out.print(atEstablishment[i][j]); 140 | if(j < atEstablishment[i].length - 1) System.out.print(","); 141 | else System.out.println("};"); 142 | } 143 | outputs[i] = bb.predictOutcome(atEstablishment[i]); 144 | System.out.println("Your code's output was: " + outputs[i]); 145 | System.out.println(); 146 | if(outputs[i].equals("FIGHT") && !fightOccurred[i] || outputs[i].equals("NO FIGHT") && fightOccurred[i]) 147 | incorrectCounter++; 148 | if(outputs[i].equals("I DON'T KNOW")) 149 | iDontKnowCounter++; 150 | System.out.println("Calling learnObservation with arguments:"); 151 | System.out.print("boolean[] atEstablishment = {"); 152 | for(int j = 0; j < atEstablishment[i].length; j++) 153 | { 154 | System.out.print(atEstablishment[i][j]); 155 | if(j < atEstablishment[i].length - 1) System.out.print(","); 156 | else System.out.println("};"); 157 | } 158 | System.out.println("boolean fightOccurred = " + fightOccurred[i]); 159 | bb.learnObservation(atEstablishment[i], fightOccurred[i]); 160 | System.out.println(); 161 | } 162 | 163 | System.out.println("Your code output " + incorrectCounter + " incorrect answers."); 164 | if(incorrectCounter != 0) System.out.println("It should not output any incorrect answers."); 165 | System.out.println("Your code output " + iDontKnowCounter + " \"I DON'T KNOW\"s."); 166 | if(iDontKnowCounter > maxIDontKnows) System.out.println("It should output \"I DON'T KNOW\" at most " + 167 | maxIDontKnows + " time."); 168 | Assert.assertTrue(incorrectCounter == 0 && iDontKnowCounter <= maxIDontKnows); 169 | } 170 | } 171 | --------------------------------------------------------------------------------