// Copyright © 2024 Mikhail Hogrefe // // This file is part of Malachite. // // Malachite is free software: you can redistribute it and/or modify it under the terms of the GNU // Lesser General Public License (LGPL) as published by the Free Software Foundation; either version // 3 of the License, or (at your option) any later version. See . use malachite_base::num::basic::integers::PrimitiveInt; use malachite_base::num::basic::signeds::PrimitiveSigned; use malachite_base::num::basic::unsigneds::PrimitiveUnsigned; use malachite_base::test_util::generators::{signed_gen, unsigned_gen}; #[test] fn test_wrapping_square() { fn test(x: T, out: T) { assert_eq!(x.wrapping_square(), out); let mut x = x; x.wrapping_square_assign(); assert_eq!(x, out); } test::(0, 0); test::(1, 1); test::(2, 4); test::(3, 9); test::(10, 100); test::(123, 15129); test::(1000, 1000000); test::(-1, 1); test::(-2, 4); test::(-3, 9); test::(-10, 100); test::(-123, 15129); test::(-1000, 1000000); test::(1000, 16960); test::(-1000, 16960); } fn wrapping_square_properties_helper_unsigned() { unsigned_gen::().test_properties(|x| { let mut square = x; square.wrapping_square_assign(); assert_eq!(square, x.wrapping_square()); assert_eq!(square, x.wrapping_pow(2)); }); } fn wrapping_square_properties_helper_signed() { signed_gen::().test_properties(|x| { let mut square = x; square.wrapping_square_assign(); assert_eq!(square, x.wrapping_square()); assert_eq!(square, x.wrapping_pow(2)); if x != T::MIN { assert_eq!((-x).wrapping_square(), square); } }); } #[test] fn saturating_square_properties() { apply_fn_to_unsigneds!(wrapping_square_properties_helper_unsigned); apply_fn_to_signeds!(wrapping_square_properties_helper_signed); }