@@ -79,4 +79,86 @@ void testLargeMessageSize() {
79
79
assertTrue (c .getWrongMess () >= 0 );
80
80
assertTrue (c .getCorrectMess () >= 0 );
81
81
}
82
+
83
+ @ Test
84
+ void testSingleBitMessage () {
85
+ CRCAlgorithm c = new CRCAlgorithm ("11" , 1 , 0.0 );
86
+ c .generateRandomMess ();
87
+ c .divideMessageWithP (false );
88
+ c .changeMess ();
89
+ c .divideMessageWithP (true );
90
+
91
+ assertTrue (c .getCorrectMess () >= 0 , "Single bit message should be handled" );
92
+ }
93
+
94
+ @ Test
95
+ void testPolynomialLongerThanMessage () {
96
+ CRCAlgorithm c = new CRCAlgorithm ("11010101" , 3 , 0.0 );
97
+ c .generateRandomMess ();
98
+ c .divideMessageWithP (false );
99
+ c .changeMess ();
100
+ c .divideMessageWithP (true );
101
+
102
+ // Should not crash, counters should be valid
103
+ assertTrue (c .getCorrectMess () + c .getWrongMess () >= 0 );
104
+ }
105
+
106
+ @ Test
107
+ void testPolynomialWithOnlyOnes () {
108
+ CRCAlgorithm c = new CRCAlgorithm ("1111" , 5 , 0.1 );
109
+ c .generateRandomMess ();
110
+ c .divideMessageWithP (false );
111
+ c .changeMess ();
112
+ c .divideMessageWithP (true );
113
+
114
+ assertTrue (c .getCorrectMess () + c .getWrongMess () >= 0 );
115
+ }
116
+
117
+ @ Test
118
+ void testMultipleRefactorCalls () {
119
+ CRCAlgorithm c = new CRCAlgorithm ("1101" , 5 , 0.2 );
120
+
121
+ for (int i = 0 ; i < 5 ; i ++) {
122
+ c .refactor ();
123
+ c .generateRandomMess ();
124
+ c .divideMessageWithP (false );
125
+ c .changeMess ();
126
+ c .divideMessageWithP (true );
127
+ }
128
+
129
+ // Counters should accumulate across multiple runs
130
+ assertTrue (c .getCorrectMess () + c .getWrongMess () > 0 );
131
+ }
132
+
133
+ @ Test
134
+ void testCounterConsistency () {
135
+ CRCAlgorithm c = new CRCAlgorithm ("1101" , 10 , 0.3 );
136
+
137
+ for (int i = 0 ; i < 100 ; i ++) {
138
+ c .refactor ();
139
+ c .generateRandomMess ();
140
+ c .divideMessageWithP (false );
141
+ c .changeMess ();
142
+ c .divideMessageWithP (true );
143
+ }
144
+
145
+ // Total messages processed should equal correct + wrong
146
+ int totalProcessed = c .getCorrectMess () + c .getWrongMess ();
147
+ assertEquals (100 , totalProcessed , "Total processed messages should equal iterations" );
148
+
149
+ // Wrong messages should equal caught + not caught
150
+ assertEquals (c .getWrongMess (), c .getWrongMessCaught () + c .getWrongMessNotCaught (), "Wrong messages should equal sum of caught and not caught" );
151
+ }
152
+
153
+ @ Test
154
+ void testGetterMethodsInitialState () {
155
+ CRCAlgorithm c = new CRCAlgorithm ("1101" , 10 , 0.1 );
156
+
157
+ // Check initial state
158
+ assertEquals (0 , c .getCorrectMess (), "Initial correct messages should be 0" );
159
+ assertEquals (0 , c .getWrongMess (), "Initial wrong messages should be 0" );
160
+ assertEquals (0 , c .getWrongMessCaught (), "Initial caught wrong messages should be 0" );
161
+ assertEquals (0 , c .getWrongMessNotCaught (), "Initial not caught wrong messages should be 0" );
162
+ }
163
+
82
164
}
0 commit comments