Compare commits
14 Commits
4d5e2db71a
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 5b69fe25b4 | |||
| 97d4d9c9a7 | |||
| e3ffd2210b | |||
| aa7dc496dc | |||
|
|
66123f6064 | ||
| 913169fe68 | |||
| 5850743394 | |||
| 79b6c10b70 | |||
| 491c531ed8 | |||
|
|
437be17f51 | ||
| 64f06ce7c1 | |||
| b613241807 | |||
|
|
13ac74132c | ||
| 35a1705570 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -4,3 +4,4 @@
|
|||||||
*.egg-info
|
*.egg-info
|
||||||
doc/_build/
|
doc/_build/
|
||||||
*.ipynb_checkpoints/
|
*.ipynb_checkpoints/
|
||||||
|
fancymath.log
|
||||||
@@ -50,3 +50,6 @@ $ pip install -e .
|
|||||||
python -m line_profiler -rmt module_to_profile.py.lprof
|
python -m line_profiler -rmt module_to_profile.py.lprof
|
||||||
> python -m line_profiler -rmt module_to_profile.py.lprof
|
> python -m line_profiler -rmt module_to_profile.py.lprof
|
||||||
```
|
```
|
||||||
|
|
||||||
|
# Day 5 Resources
|
||||||
|
- [5 Worlds](https://www.joelonsoftware.com/2002/05/06/five-worlds/) from Joel Spolsky's blog.
|
||||||
|
|||||||
@@ -17,7 +17,13 @@ release = '0.0.1'
|
|||||||
extensions = ["sphinx.ext.autodoc", "sphinx.ext.viewcode"]
|
extensions = ["sphinx.ext.autodoc", "sphinx.ext.viewcode"]
|
||||||
|
|
||||||
templates_path = ['_templates']
|
templates_path = ['_templates']
|
||||||
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '.ipynb_checkpoints']
|
exclude_patterns = [
|
||||||
|
'_build',
|
||||||
|
'Thumbs.db',
|
||||||
|
'.DS_Store',
|
||||||
|
'.ipynb_checkpoints',
|
||||||
|
'api/.ipynb_checkpoints'
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,14 @@ class Vector(object):
|
|||||||
z = self.z + other.z
|
z = self.z + other.z
|
||||||
return self.__class__(x, y, z)
|
return self.__class__(x, y, z)
|
||||||
|
|
||||||
|
def __mul__(self, other):
|
||||||
|
if not isinstance(other, Vector):
|
||||||
|
return NotImplemented
|
||||||
|
x = self.y * other.z - self.z * other.y
|
||||||
|
y = self.z * other.x - self.x * other.z
|
||||||
|
z = self.x * other.y - self.y * other.x
|
||||||
|
return self.__class__(x, y, z)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
v1 = Vector(3, 4, 0)
|
v1 = Vector(3, 4, 0)
|
||||||
|
|||||||
@@ -4,13 +4,47 @@ from fancymath.vector import Vector
|
|||||||
|
|
||||||
|
|
||||||
class TestVector(unittest.TestCase):
|
class TestVector(unittest.TestCase):
|
||||||
|
def test_cross_product(self):
|
||||||
|
# Dictionary of (v1, v2): v3
|
||||||
|
values = {
|
||||||
|
(Vector(1, 2, 3), Vector(3, 2, 1)): Vector(-4, 8, -4),
|
||||||
|
(Vector(0, 0, 0), Vector(1, 2, 3)): Vector(0, 0, 0),
|
||||||
|
(Vector(1, 0, 0), Vector(1, 0, 0)): Vector(0, 0, 0),
|
||||||
|
}
|
||||||
|
|
||||||
|
for inputs, expected in values.items():
|
||||||
|
v1, v2 = inputs
|
||||||
|
with self.subTest(v1=v1, v2=v2):
|
||||||
|
v3 = v1 * v2
|
||||||
|
|
||||||
|
self.assertIsInstance(v3, Vector)
|
||||||
|
self.assertEqual(v3.x, expected.x)
|
||||||
|
self.assertEqual(v3.y, expected.y)
|
||||||
|
self.assertEqual(v3.z, expected.z)
|
||||||
|
|
||||||
|
def test_cross_product_failure(self):
|
||||||
|
v1 = Vector(1, 2, 3)
|
||||||
|
v2 = (3, 2, 1)
|
||||||
|
|
||||||
|
with self.assertRaises(TypeError):
|
||||||
|
v1 * v2
|
||||||
|
|
||||||
|
|
||||||
def test_add_vector(self):
|
def test_add_vector(self):
|
||||||
v1 = Vector(1, 2, 3)
|
v1 = Vector(1, 2, 3)
|
||||||
v2 = Vector(-3, -2, -1)
|
v2 = Vector(-3, -2, -1)
|
||||||
v3 = v1 + v2
|
v3 = v1 + v2
|
||||||
self.assertIsInstance(v3, Vector)
|
self.assertIsInstance(v3, Vector)
|
||||||
self.assertEqual(v3.x, v1.x + v2.x)
|
self.assertEqual(v3.x, v1.x + v2.x)
|
||||||
|
|
||||||
|
def test_abs(self):
|
||||||
|
v1 = Vector(0, 0, 0)
|
||||||
|
v2 = Vector(1, 2, 2)
|
||||||
|
v3 = Vector(1, -2, 2)
|
||||||
|
self.assertEqual(v1.abs(), 0)
|
||||||
|
self.assertEqual(v2.abs(), 3)
|
||||||
|
self.assertEqual(v2.abs(), v3.abs())
|
||||||
|
|
||||||
def test_dot_failure(self):
|
def test_dot_failure(self):
|
||||||
with self.assertRaises(ValueError):
|
with self.assertRaises(ValueError):
|
||||||
v1 = Vector(1, 2, 3)
|
v1 = Vector(1, 2, 3)
|
||||||
|
|||||||
Reference in New Issue
Block a user