@@ -188,46 +188,65 @@ end
188188run_rust_test " factorization"
189189validate_test " Integer Factorization" 9
190190
191- # # Test 6: Exact roots
192- # echo -e "${BLUE}6. EXACT ROOTS${NC}"
193- # run_scilab_test "Exact Roots" '
194- # // Perfect squares
195- # squares = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100];
196- # for i = 1:length(squares)
197- # n = squares(i);
198- # root = sqrt(n);
199- # printf("sqrt(%d) = %d (exact)\n", n, root);
200- # end
201-
202- # // Perfect cubes (positive)
203- # cubes_pos = [1, 8, 27, 64, 125];
204- # expected_roots_pos = [1, 2, 3, 4, 5];
205- # for i = 1:length(cubes_pos)
206- # n = cubes_pos(i);
207- # root = expected_roots_pos(i);
208- # printf("cbrt(%d) = %d (exact)\n", n, root);
209- # end
210-
211- # // Perfect cubes (negative)
212- # cubes_neg = [-1, -8, -27, -64, -125];
213- # expected_roots_neg = [-1, -2, -3, -4, -5];
214- # for i = 1:length(cubes_neg)
215- # n = cubes_neg(i);
216- # root = expected_roots_neg(i);
217- # printf("cbrt(%d) = %d (exact)\n", n, root);
218- # end
219-
220- # // Even roots of negative numbers (should return None)
221- # // Test case for issue #25: nth_root_exact panic on negative even roots
222- # printf("-1^(1/2) = None (imaginary)\n");
223- # printf("-4^(1/2) = None (imaginary)\n");
224- # printf("-8^(1/4) = None (imaginary)\n");
225- # printf("-16^(1/4) = None (imaginary)\n");
226- # printf("-25^(1/2) = None (imaginary)\n");
227- # '
228-
229- # run_rust_test "exact_roots"
230- # validate_test "Exact Roots" 25
191+ # Test 6: Exact roots
192+ echo -e " ${BLUE} 6. EXACT ROOTS${NC} "
193+ run_scilab_test " Exact Roots" '
194+ // Perfect squares
195+ squares = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100];
196+ for i = 1:length(squares)
197+ n = squares(i);
198+ root = sqrt(n);
199+ printf("sqrt(%d) = %d (exact)\n", n, root);
200+ end
201+
202+ // Perfect cubes (positive)
203+ cubes_pos = [1, 8, 27, 64, 125];
204+ expected_roots_pos = [1, 2, 3, 4, 5];
205+ for i = 1:length(cubes_pos)
206+ n = cubes_pos(i);
207+ root = expected_roots_pos(i);
208+ printf("cbrt(%d) = %d (exact)\n", n, root);
209+ end
210+
211+ // Perfect cubes (negative)
212+ cubes_neg = [-1, -8, -27, -64, -125];
213+ expected_roots_neg = [-1, -2, -3, -4, -5];
214+ for i = 1:length(cubes_neg)
215+ n = cubes_neg(i);
216+ root = expected_roots_neg(i);
217+ printf("cbrt(%d) = %d (exact)\n", n, root);
218+ end
219+
220+ // Even roots of negative numbers (should return None)
221+ // Test case for issue #25: nth_root_exact panic on negative even roots
222+ printf("-1 nth_root_exact(2) = None\n");
223+ printf("-4 nth_root_exact(2) = None\n");
224+ printf("-8 nth_root_exact(4) = None\n");
225+ printf("-16 nth_root_exact(4) = None\n");
226+ printf("-25 nth_root_exact(2) = None\n");
227+
228+ // Odd roots of negative numbers (should work)
229+ printf("-8 nth_root_exact(3) = -2\n");
230+ printf("-27 nth_root_exact(3) = -3\n");
231+ printf("-32 nth_root_exact(5) = -2\n");
232+
233+ // Additional nth_root_exact tests for positive numbers
234+ printf("16 nth_root_exact(4) = 2\n");
235+ printf("32 nth_root_exact(5) = 2\n");
236+ printf("81 nth_root_exact(4) = 3\n");
237+ printf("243 nth_root_exact(5) = 3\n");
238+
239+ // Test various signed integer type limits from patch
240+ printf("-1i8 nth_root_exact(2) = None\n");
241+ printf("-1i16 nth_root_exact(2) = None\n");
242+ printf("-1i32 nth_root_exact(2) = None\n");
243+ printf("-1i64 nth_root_exact(2) = None\n");
244+ printf("-1i128 nth_root_exact(2) = None\n");
245+ printf("-1isize nth_root_exact(2) = None\n");
246+ '
247+
248+ run_rust_test " exact_roots"
249+ validate_test " Exact Roots" 31
231250
232251# Test 7: Large numbers
233252echo -e " ${BLUE} 7. LARGE NUMBERS${NC} "
0 commit comments