| 1 | from decimal import Decimal |
| 2 | |
| 3 | import pytest |
| 4 | |
| 5 | from isoduration.operations import max_day_in_month, mod2, mod3, quot2, quot3 |
| 6 | |
| 7 | |
| 8 | @pytest.mark.parametrize( |
| 9 | "op1, op2, result", |
| 10 | ( |
| 11 | ("-1", "3", "-1"), |
| 12 | ("0", "3", "0"), |
| 13 | ("1", "3", "0"), |
| 14 | ("2", "3", "0"), |
| 15 | ("3", "3", "1"), |
| 16 | ("3.123", "3", "1"), |
| 17 | ), |
| 18 | ) |
| 19 | def test_f_quotient_2(op1, op2, result): |
| 20 | assert quot2(Decimal(op1), Decimal(op2)) == Decimal(result) |
| 21 | |
| 22 | |
| 23 | @pytest.mark.parametrize( |
| 24 | "op1, op2, result", |
| 25 | ( |
| 26 | ("-1", "3", "2"), |
| 27 | ("0", "3", "0"), |
| 28 | ("1", "3", "1"), |
| 29 | ("2", "3", "2"), |
| 30 | ("3", "3", "0"), |
| 31 | ("3.123", "3", "0.123"), |
| 32 | ), |
| 33 | ) |
| 34 | def test_modulo_2(op1, op2, result): |
| 35 | assert mod2(Decimal(op1), Decimal(op2)) == Decimal(result) |
| 36 | |
| 37 | |
| 38 | @pytest.mark.parametrize( |
| 39 | "op1, op2, op3, result", |
| 40 | ( |
| 41 | ("0", "1", "13", "-1"), |
| 42 | ("1", "1", "13", "0"), |
| 43 | ("2", "1", "13", "0"), |
| 44 | ("3", "1", "13", "0"), |
| 45 | ("4", "1", "13", "0"), |
| 46 | ("5", "1", "13", "0"), |
| 47 | ("6", "1", "13", "0"), |
| 48 | ("7", "1", "13", "0"), |
| 49 | ("8", "1", "13", "0"), |
| 50 | ("9", "1", "13", "0"), |
| 51 | ("10", "1", "13", "0"), |
| 52 | ("11", "1", "13", "0"), |
| 53 | ("12", "1", "13", "0"), |
| 54 | ("13", "1", "13", "1"), |
| 55 | ("13.123", "1", "13", "1"), |
| 56 | ), |
| 57 | ) |
| 58 | def test_f_quotient_3(op1, op2, op3, result): |
| 59 | assert quot3(Decimal(op1), Decimal(op2), Decimal(op3)) == Decimal(result) |
| 60 | |
| 61 | |
| 62 | @pytest.mark.parametrize( |
| 63 | "op1, op2, op3, result", |
| 64 | ( |
| 65 | ("0", "1", "13", "12"), |
| 66 | ("1", "1", "13", "1"), |
| 67 | ("2", "1", "13", "2"), |
| 68 | ("3", "1", "13", "3"), |
| 69 | ("4", "1", "13", "4"), |
| 70 | ("5", "1", "13", "5"), |
| 71 | ("6", "1", "13", "6"), |
| 72 | ("7", "1", "13", "7"), |
| 73 | ("8", "1", "13", "8"), |
| 74 | ("9", "1", "13", "9"), |
| 75 | ("10", "1", "13", "10"), |
| 76 | ("11", "1", "13", "11"), |
| 77 | ("12", "1", "13", "12"), |
| 78 | ("13", "1", "13", "1"), |
| 79 | ("13.123", "1", "13", "1.123"), |
| 80 | ), |
| 81 | ) |
| 82 | def test_modulo_3(op1, op2, op3, result): |
| 83 | assert mod3(Decimal(op1), Decimal(op2), Decimal(op3)) == Decimal(result) |
| 84 | |
| 85 | |
| 86 | @pytest.mark.parametrize( |
| 87 | "year, month, max_day", |
| 88 | ( |
| 89 | (1987, 1, 31), |
| 90 | (1987, 2, 28), |
| 91 | (1987, 3, 31), |
| 92 | (1987, 4, 30), |
| 93 | (1987, 5, 31), |
| 94 | (1987, 6, 30), |
| 95 | (1987, 7, 31), |
| 96 | (1987, 8, 31), |
| 97 | (1987, 9, 30), |
| 98 | (1987, 10, 31), |
| 99 | (1987, 11, 30), |
| 100 | (1987, 12, 31), |
| 101 | (1987, 12, 31), |
| 102 | (2000, 2, 29), |
| 103 | (1900, 2, 28), |
| 104 | (2004, 2, 29), |
| 105 | ), |
| 106 | ) |
| 107 | def test_max_day_in_month(year, month, max_day): |
| 108 | assert max_day_in_month(Decimal(year), Decimal(month)) == Decimal(max_day) |