(self)
| 153 | return |
| 154 | |
| 155 | def test_monomial_substitution(self): |
| 156 | # Test with int. |
| 157 | self.assertAlmostEqual(self.m7.substitute(2), -16 * math.pi, delta=1e-9) |
| 158 | # Test with float. |
| 159 | self.assertAlmostEqual(self.m7.substitute(1.5), (1.5**4) * -math.pi, delta=1e-9) |
| 160 | # Test with Fraction. |
| 161 | self.assertAlmostEqual( |
| 162 | self.m7.substitute(Fraction(-1, 2)), |
| 163 | (Fraction(-1, 2) ** 4) * -math.pi, |
| 164 | delta=1e-9, |
| 165 | ) |
| 166 | # Test with a complete substitution map. |
| 167 | self.assertAlmostEqual( |
| 168 | self.m7.substitute({1: 3, 7: 0}), (3**2) * (0**2) * -math.pi, delta=1e-9 |
| 169 | ) |
| 170 | # Test with a more than complete substitution map. |
| 171 | self.assertAlmostEqual( |
| 172 | self.m7.substitute({1: 3, 7: 0, 2: 2}), |
| 173 | (3**2) * (0**2) * -math.pi, |
| 174 | delta=1e-9, |
| 175 | ) |
| 176 | |
| 177 | # Should raise a ValueError if not enough variables are supplied! |
| 178 | self.assertRaises( |
| 179 | ValueError, lambda x, y: x.substitute(y), self.m7, {1: 3, 2: 2} |
| 180 | ) |
| 181 | self.assertRaises(ValueError, lambda x, y: x.substitute(y), self.m7, {2: 2}) |
| 182 | |
| 183 | # The zero monomial always gives zero upon substitution. |
| 184 | self.assertEqual(self.m8.substitute(2), 0) |
| 185 | self.assertEqual(self.m8.substitute({1231: 2, 1: 2}), 0) |
| 186 | |
| 187 | return |
| 188 | |
| 189 | def test_monomial_all_variables(self): |
| 190 |
nothing calls this directly
no test coverage detected