/// Tests for fractions /// includes simple fractions and more complex fractions /// also tests mixed fractions (implicit and explicit) use crate::common::*; #[test] fn common_fraction_half() { let expr = " 1 2 "; test("en", "ClearSpeak", expr, "1 half"); } #[test] fn common_fraction_thirds() { let expr = " 2 3 "; test("en", "ClearSpeak", expr, "2 thirds"); } #[test] fn common_fraction_tenths() { let expr = " 17 10 "; test_prefs("en", "ClearSpeak", vec![("Verbosity", "Medium"), ("ClearSpeak_Fractions", "Auto")], expr, "17 tenths"); test_prefs("en", "ClearSpeak", vec![("Verbosity", "Medium"), ("ClearSpeak_Fractions", "Ordinal")], expr, "17 tenths"); } #[test] #[allow(non_snake_case)] fn not_ClearSpeak_common_fraction_tenths() { let expr = " 89 10 "; test_prefs("en", "ClearSpeak", vec![("Verbosity", "Medium"), ("ClearSpeak_Fractions", "Auto")], expr, "89 over 10"); test_prefs("en", "ClearSpeak", vec![("Verbosity", "Medium"), ("ClearSpeak_Fractions", "Ordinal")], expr, "89 tenths"); } #[test] fn non_simple_fraction() { let expr = " x+y x-y "; test_prefs("en", "ClearSpeak", vec![("Verbosity", "Medium"), ("ClearSpeak_Fractions", "Auto")], expr, "the fraction with numerator; x plus y; and denominator x minus y;"); test_prefs("en", "ClearSpeak", vec![("Verbosity", "Medium"), ("ClearSpeak_Fractions", "Ordinal")], expr, "the fraction with numerator; x plus y; and denominator x minus y;"); test_prefs("en", "ClearSpeak", vec![("Verbosity", "Medium"), ("ClearSpeak_Fractions", "Over")], expr, "x plus y over x minus y"); test_prefs("en", "ClearSpeak", vec![("Verbosity", "Medium"), ("ClearSpeak_Fractions", "FracOver")], expr, "the fraction x plus y over x minus y"); test_prefs("en", "ClearSpeak", vec![("Verbosity", "Medium"), ("ClearSpeak_Fractions", "General")], expr, "the fraction with numerator; x plus y; and denominator x minus y;"); test_prefs("en", "ClearSpeak", vec![("Verbosity", "Medium"), ("ClearSpeak_Fractions", "EndFrac")], expr, "the fraction with numerator; x plus y; and denominator x minus y; end fraction,"); test_prefs("en", "ClearSpeak", vec![("Verbosity", "Medium"), ("ClearSpeak_Fractions", "GeneralEndFrac")], expr, "the fraction with numerator; x plus y; and denominator x minus y; end fraction,"); test_prefs("en", "ClearSpeak", vec![("Verbosity", "Medium"), ("ClearSpeak_Fractions", "OverEndFrac")], expr, "x plus y over x minus y, end fraction,"); test_prefs("en", "ClearSpeak", vec![("Verbosity", "Medium"), ("ClearSpeak_Fractions", "Per")], expr, "x plus y per x minus y"); test_prefs("en", "ClearSpeak", vec![("Verbosity", "Verbose"),("ClearSpeak_Fractions", "Auto")], expr, "the fraction with numerator; x plus y; and denominator x minus y; end fraction,"); } #[test] fn mixed_number() { let expr = " 3 1 2 "; test("en", "ClearSpeak", expr, "3 and 1 half"); } #[test] fn explicit_mixed_number() { let expr = " 3 1 8 "; test("en", "ClearSpeak", expr, "3 and 1 eighth"); } #[test] fn mixed_number_big() { let expr = " 3 7 83 "; test("en", "ClearSpeak", expr, "3 and 7 over 83"); } #[test] fn simple_text() { let expr = " rise run "; test("en", "ClearSpeak", expr, "rise over run"); } #[test] fn number_and_text() { let expr = " 2miles 3gallons "; test("en", "ClearSpeak", expr, "2 miles over 3 gallons"); } #[test] fn nested_simple_fractions() { let expr = " 1 2 2 3 "; test_prefs("en", "ClearSpeak", vec![("ClearSpeak_Fractions", "Auto")], expr, "1 half over 2 thirds"); test_prefs("en", "ClearSpeak", vec![("ClearSpeak_Fractions", "Ordinal")], expr, "1 half over 2 thirds"); test_prefs("en", "ClearSpeak", vec![("ClearSpeak_Fractions", "Over")], expr, "1 over 2 over 2 over 3"); test_prefs("en", "ClearSpeak", vec![("ClearSpeak_Fractions", "FracOver")], expr, "the fraction the fraction 1 over 2 over the fraction 2 over 3"); test_prefs("en", "ClearSpeak", vec![("ClearSpeak_Fractions", "General")], expr, "the fraction with numerator the fraction with numerator 1; and denominator 2; and denominator the fraction with numerator 2; and denominator 3;"); test_prefs("en", "ClearSpeak", vec![("ClearSpeak_Fractions", "EndFrac")], expr, "1 half over 2 thirds"); test_prefs("en", "ClearSpeak", vec![("ClearSpeak_Fractions", "GeneralEndFrac")], expr, "the fraction with numerator the fraction with numerator 1; and denominator 2; end fraction; and denominator the fraction with numerator 2; and denominator 3; end fraction; end fraction,"); test_prefs("en", "ClearSpeak", vec![("ClearSpeak_Fractions", "OverEndFrac")], expr, "1 over 2, end fraction, over 2 over 3, end fraction; end fraction,"); } #[test] fn semi_nested_fraction() { let expr = " 2 3 x 6 "; test("en", "ClearSpeak", expr, "2 thirds x over 6"); } #[test] fn general_nested_fraction() { let expr = " 10 n 2 n "; test("en", "ClearSpeak", expr, "the fraction with numerator; 10 over n; and denominator 2 over n;"); } #[test] fn complex_nested_fraction() { let expr = " n + 10 n 2 n "; test("en", "ClearSpeak", expr, "the fraction with numerator; the fraction with numerator; n plus 10; and denominator n; and denominator 2 over n;"); } #[test] fn simple_function() { let expr = "f(x)2"; test_prefs("en", "ClearSpeak", vec![("Verbosity", "Medium"), ("ClearSpeak_Fractions", "Auto")], expr, "f of x over 2"); test_prefs("en", "ClearSpeak", vec![("Verbosity", "Verbose"), ("ClearSpeak_Fractions", "Auto")], expr, "f of x over 2, end fraction,"); } #[test] fn function_over_function() { let expr = " f(x) g(x) "; test_prefs("en", "ClearSpeak", vec![("Verbosity", "Medium"), ("ClearSpeak_Fractions", "Auto")], expr, "f of x over g of x"); test_prefs("en", "ClearSpeak", vec![("Verbosity", "Verbose"), ("ClearSpeak_Fractions", "Auto")], expr, "f of x over g of x, end fraction,"); } #[test] fn non_simple_function_over_function() { let expr = " f(x+1) g(x) "; test_prefs("en", "ClearSpeak", vec![("Verbosity", "Medium"), ("ClearSpeak_Fractions", "Auto")], expr, "the fraction with numerator; f of, open paren x plus 1, close paren; and denominator g of x;"); test_prefs("en", "ClearSpeak", vec![("Verbosity", "Verbose"), ("ClearSpeak_Fractions", "Auto")], expr, "the fraction with numerator; f of, open paren x plus 1, close paren; and denominator g of x; end fraction,"); } #[test] fn binomial() { let expr = " 2 ( 7 3 ) "; test("en", "ClearSpeak", expr, "2 times 7 choose 3"); }