github.com/vpayno/adventofcode-2022-golang-workspace@v0.0.0-20230605190011-dbafed5593de/internal/day02/init_test.go (about) 1 package day02 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func TestSetup(t *testing.T) { 10 appName := "testName" 11 12 want := Config{ 13 appName: appName, 14 inputFileName: "data/" + appName + "/" + appName + "-input.txt", 15 } 16 17 got := Setup(appName) 18 19 assert.Equal(t, want.appName, got.appName, "app names aren't equal") 20 assert.Equal(t, want.inputFileName, got.inputFileName, "input file names aren't equal") 21 } 22 23 // Seems like a silly test but any changes to these valuse will break the rest of the logic. 24 func TestPronoun_values(t *testing.T) { 25 assert.Equal(t, int(them), 0) 26 assert.Equal(t, int(goal), 1) 27 } 28 29 // Seems like a silly test but any changes to these valuse will break the rest of the logic. 30 func TestOutcomes_values(t *testing.T) { 31 assert.Equal(t, int(loose), 0) 32 assert.Equal(t, int(draw), 3) 33 assert.Equal(t, int(win), 6) 34 } 35 36 // Seems like a silly test but any changes to these valuse will break the rest of the logic. 37 func TestOutcomes_strings(t *testing.T) { 38 assert.Equal(t, outcomeNames[loose], "loose") 39 assert.Equal(t, outcomeNames[draw], "draw") 40 assert.Equal(t, outcomeNames[win], "win") 41 } 42 43 // Seems like a silly test but any changes to these valuse will break the rest of the logic. 44 func TestMoves_values(t *testing.T) { 45 assert.Equal(t, int(rock), 1) 46 assert.Equal(t, int(paper), 2) 47 assert.Equal(t, int(scissors), 3) 48 } 49 50 // Seems like a silly test but any changes to these valuse will break the rest of the logic. 51 func TestMoves_strings(t *testing.T) { 52 assert.Equal(t, moveNames[rock], "rock") 53 assert.Equal(t, moveNames[paper], "paper") 54 assert.Equal(t, moveNames[scissors], "scissors") 55 } 56 57 // Seems like a silly test but any changes to these valuse will break the rest of the logic. 58 func TestString2Move(t *testing.T) { 59 assert.Equal(t, int(string2move["A"]), int(rock)) 60 assert.Equal(t, int(string2move["B"]), int(paper)) 61 assert.Equal(t, int(string2move["C"]), int(scissors)) 62 } 63 64 // Seems like a silly test but any changes to these valuse will break the rest of the logic. 65 func TestString2Outcome(t *testing.T) { 66 assert.Equal(t, int(string2outcome["X"]), int(loose)) 67 assert.Equal(t, int(string2outcome["Y"]), int(draw)) 68 assert.Equal(t, int(string2outcome["Z"]), int(win)) 69 } 70 71 func TestRound_yourMove(t *testing.T) { 72 r := round{ 73 them: rock, 74 goal: win, 75 } 76 assert.Equal(t, int(paper), int(r.yourMove()), "paper vs rock != win") 77 78 r = round{ 79 them: scissors, 80 goal: win, 81 } 82 assert.Equal(t, int(rock), int(r.yourMove()), "rock vs scissors != win") 83 84 r = round{ 85 them: paper, 86 goal: win, 87 } 88 assert.Equal(t, int(scissors), int(r.yourMove()), "scissors vs paper != win") 89 90 r = round{ 91 them: rock, 92 goal: loose, 93 } 94 assert.Equal(t, int(scissors), int(r.yourMove()), "scissors vs rock != loose") 95 96 r = round{ 97 them: scissors, 98 goal: loose, 99 } 100 assert.Equal(t, int(paper), int(r.yourMove()), "paper vs scissors != loose") 101 102 r = round{ 103 them: paper, 104 goal: loose, 105 } 106 assert.Equal(t, int(rock), int(r.yourMove()), "rock vs paper != loose") 107 108 r = round{ 109 them: rock, 110 goal: draw, 111 } 112 assert.Equal(t, int(r.them), int(r.yourMove()), "scissors vs rock != draw") 113 114 r = round{ 115 them: scissors, 116 goal: draw, 117 } 118 assert.Equal(t, int(r.them), int(r.yourMove()), "scissors vs scissors != draw") 119 120 r = round{ 121 them: paper, 122 goal: draw, 123 } 124 assert.Equal(t, int(r.them), int(r.yourMove()), "paper vs paper != draw") 125 } 126 127 func TestRound_score(t *testing.T) { 128 r := round{ 129 them: paper, 130 goal: loose, 131 } 132 assert.Equal(t, r.score(), int(loose)+int(rock), "loose+rock != 1") 133 134 r = round{ 135 them: scissors, 136 goal: loose, 137 } 138 assert.Equal(t, r.score(), int(loose)+int(paper), "loose+paper != 2") 139 140 r = round{ 141 them: rock, 142 goal: loose, 143 } 144 assert.Equal(t, r.score(), int(loose)+int(scissors), "loose+scissors != 3") 145 146 r = round{ 147 them: rock, 148 goal: draw, 149 } 150 assert.Equal(t, r.score(), int(draw)+int(rock), "draw+rock != 4") 151 152 r = round{ 153 them: paper, 154 goal: draw, 155 } 156 assert.Equal(t, r.score(), int(draw)+int(paper), "draw+paper != 5") 157 158 r = round{ 159 them: scissors, 160 goal: draw, 161 } 162 assert.Equal(t, r.score(), int(draw)+int(scissors), "draw+scissors != 6") 163 164 r = round{ 165 them: scissors, 166 goal: win, 167 } 168 assert.Equal(t, r.score(), int(win)+int(rock), "win+rock != 7") 169 170 r = round{ 171 them: rock, 172 goal: win, 173 } 174 assert.Equal(t, r.score(), int(win)+int(paper), "win+paper != 8") 175 176 r = round{ 177 them: paper, 178 goal: win, 179 } 180 assert.Equal(t, r.score(), int(win)+int(scissors), "win+scissors != 9") 181 } 182 183 func TestRound_update(t *testing.T) { 184 want := round{ 185 them: paper, 186 goal: win, 187 } 188 189 s := []move{paper, move(win)} 190 got := new(round) 191 got.update(s) 192 193 assert.Equal(t, want.them, got.them) 194 assert.Equal(t, want.goal, got.goal) 195 }