use moleco::{calculate_scheme, modulo}; use num_bigint::BigUint; use num_traits::One; /// Main test to check if the calculate_scheme function works stable. /// If values changed, it means the hashing algorithm changed. #[test] fn test_calculate_scheme() { let scheme = calculate_scheme("water".to_string()).unwrap(); assert_eq!(scheme.primary.hue, 133); assert_eq!(scheme.first_accent.hue, 163); assert_eq!(scheme.second_accent.hue, 16); assert_eq!(scheme.complementary.hue, 312); let scheme2 = calculate_scheme("InChI=1S/water".to_string()).unwrap(); assert_eq!(scheme2.primary.hue, scheme.primary.hue); assert_eq!(scheme2.first_accent.hue, scheme.first_accent.hue); assert_eq!(scheme2.second_accent.hue, scheme.second_accent.hue); assert_eq!(scheme2.complementary.hue, scheme.complementary.hue); // Test attempt to generate proper scheme with no version given let scheme3 = calculate_scheme("InChI=/water".to_string()).unwrap(); assert_eq!(scheme3.primary.hue, scheme.primary.hue); assert_eq!(scheme3.first_accent.hue, scheme.first_accent.hue); assert_eq!(scheme3.second_accent.hue, scheme.second_accent.hue); assert_eq!(scheme3.complementary.hue, scheme.complementary.hue); } /// Test to check if the function errors on input with InChi= prefix but no slash. #[test] #[should_panic] fn test_calculate_wrong_input_1() { calculate_scheme("InChI=water".to_string()).unwrap(); } #[test] #[should_panic] fn test_calculate_wrong_input_2() { calculate_scheme("InChI=1S/".to_string()).unwrap(); } /// Function copied from biguint docs. fn fib(n: usize) -> BigUint { let mut f0 = BigUint::ZERO; let mut f1 = BigUint::one(); for _ in 0..n { let f2 = f0 + &f1; f0 = f1; f1 = f2; } f0 } #[test] fn test_modulo() { assert_eq!(modulo(&fib(1000), 511), 119); }