@@ -36,11 +36,11 @@ public class VirtualMachineTest { |
36 | 36 |
|
37 | 37 | @Test |
38 | 38 | public void testLiteral() { |
39 | | - int[] bytecode = new int[2]; |
| 39 | + var bytecode = new int[2]; |
40 | 40 | bytecode[0] = LITERAL.getIntValue(); |
41 | 41 | bytecode[1] = 10; |
42 | 42 |
|
43 | | - VirtualMachine vm = new VirtualMachine(); |
| 43 | + var vm = new VirtualMachine(); |
44 | 44 | vm.execute(bytecode); |
45 | 45 |
|
46 | 46 | assertEquals(1, vm.getStack().size()); |
@@ -49,56 +49,56 @@ public void testLiteral() { |
49 | 49 |
|
50 | 50 | @Test |
51 | 51 | public void testSetHealth() { |
52 | | - int wizardNumber = 0; |
53 | | - int[] bytecode = new int[5]; |
| 52 | + var wizardNumber = 0; |
| 53 | + var bytecode = new int[5]; |
54 | 54 | bytecode[0] = LITERAL.getIntValue(); |
55 | 55 | bytecode[1] = wizardNumber; |
56 | 56 | bytecode[2] = LITERAL.getIntValue(); |
57 | 57 | bytecode[3] = 50; // health amount |
58 | 58 | bytecode[4] = SET_HEALTH.getIntValue(); |
59 | 59 |
|
60 | | - VirtualMachine vm = new VirtualMachine(); |
| 60 | + var vm = new VirtualMachine(); |
61 | 61 | vm.execute(bytecode); |
62 | 62 |
|
63 | 63 | assertEquals(50, vm.getWizards()[wizardNumber].getHealth()); |
64 | 64 | } |
65 | 65 |
|
66 | 66 | @Test |
67 | 67 | public void testSetAgility() { |
68 | | - int wizardNumber = 0; |
69 | | - int[] bytecode = new int[5]; |
| 68 | + var wizardNumber = 0; |
| 69 | + var bytecode = new int[5]; |
70 | 70 | bytecode[0] = LITERAL.getIntValue(); |
71 | 71 | bytecode[1] = wizardNumber; |
72 | 72 | bytecode[2] = LITERAL.getIntValue(); |
73 | 73 | bytecode[3] = 50; // agility amount |
74 | 74 | bytecode[4] = SET_AGILITY.getIntValue(); |
75 | 75 |
|
76 | | - VirtualMachine vm = new VirtualMachine(); |
| 76 | + var vm = new VirtualMachine(); |
77 | 77 | vm.execute(bytecode); |
78 | 78 |
|
79 | 79 | assertEquals(50, vm.getWizards()[wizardNumber].getAgility()); |
80 | 80 | } |
81 | 81 |
|
82 | 82 | @Test |
83 | 83 | public void testSetWisdom() { |
84 | | - int wizardNumber = 0; |
85 | | - int[] bytecode = new int[5]; |
| 84 | + var wizardNumber = 0; |
| 85 | + var bytecode = new int[5]; |
86 | 86 | bytecode[0] = LITERAL.getIntValue(); |
87 | 87 | bytecode[1] = wizardNumber; |
88 | 88 | bytecode[2] = LITERAL.getIntValue(); |
89 | 89 | bytecode[3] = 50; // wisdom amount |
90 | 90 | bytecode[4] = SET_WISDOM.getIntValue(); |
91 | 91 |
|
92 | | - VirtualMachine vm = new VirtualMachine(); |
| 92 | + var vm = new VirtualMachine(); |
93 | 93 | vm.execute(bytecode); |
94 | 94 |
|
95 | 95 | assertEquals(50, vm.getWizards()[wizardNumber].getWisdom()); |
96 | 96 | } |
97 | 97 |
|
98 | 98 | @Test |
99 | 99 | public void testGetHealth() { |
100 | | - int wizardNumber = 0; |
101 | | - int[] bytecode = new int[8]; |
| 100 | + var wizardNumber = 0; |
| 101 | + var bytecode = new int[8]; |
102 | 102 | bytecode[0] = LITERAL.getIntValue(); |
103 | 103 | bytecode[1] = wizardNumber; |
104 | 104 | bytecode[2] = LITERAL.getIntValue(); |
@@ -108,21 +108,21 @@ public void testGetHealth() { |
108 | 108 | bytecode[6] = wizardNumber; |
109 | 109 | bytecode[7] = GET_HEALTH.getIntValue(); |
110 | 110 |
|
111 | | - VirtualMachine vm = new VirtualMachine(); |
| 111 | + var vm = new VirtualMachine(); |
112 | 112 | vm.execute(bytecode); |
113 | 113 |
|
114 | 114 | assertEquals(Integer.valueOf(50), vm.getStack().pop()); |
115 | 115 | } |
116 | 116 |
|
117 | 117 | @Test |
118 | 118 | public void testPlaySound() { |
119 | | - int wizardNumber = 0; |
120 | | - int[] bytecode = new int[3]; |
| 119 | + var wizardNumber = 0; |
| 120 | + var bytecode = new int[3]; |
121 | 121 | bytecode[0] = LITERAL.getIntValue(); |
122 | 122 | bytecode[1] = wizardNumber; |
123 | 123 | bytecode[2] = PLAY_SOUND.getIntValue(); |
124 | 124 |
|
125 | | - VirtualMachine vm = new VirtualMachine(); |
| 125 | + var vm = new VirtualMachine(); |
126 | 126 | vm.execute(bytecode); |
127 | 127 |
|
128 | 128 | assertEquals(0, vm.getStack().size()); |
@@ -131,13 +131,13 @@ public void testPlaySound() { |
131 | 131 |
|
132 | 132 | @Test |
133 | 133 | public void testSpawnParticles() { |
134 | | - int wizardNumber = 0; |
135 | | - int[] bytecode = new int[3]; |
| 134 | + var wizardNumber = 0; |
| 135 | + var bytecode = new int[3]; |
136 | 136 | bytecode[0] = LITERAL.getIntValue(); |
137 | 137 | bytecode[1] = wizardNumber; |
138 | 138 | bytecode[2] = SPAWN_PARTICLES.getIntValue(); |
139 | 139 |
|
140 | | - VirtualMachine vm = new VirtualMachine(); |
| 140 | + var vm = new VirtualMachine(); |
141 | 141 | vm.execute(bytecode); |
142 | 142 |
|
143 | 143 | assertEquals(0, vm.getStack().size()); |
@@ -146,9 +146,9 @@ public void testSpawnParticles() { |
146 | 146 |
|
147 | 147 | @Test |
148 | 148 | public void testInvalidInstruction() { |
149 | | - int[] bytecode = new int[1]; |
| 149 | + var bytecode = new int[1]; |
150 | 150 | bytecode[0] = 999; |
151 | | - VirtualMachine vm = new VirtualMachine(); |
| 151 | + var vm = new VirtualMachine(); |
152 | 152 |
|
153 | 153 | assertThrows(IllegalArgumentException.class, () -> vm.execute(bytecode)); |
154 | 154 | } |
|