Skip to content

Commit 3ab88fb

Browse files
committed
Add extra tests
1 parent f088d13 commit 3ab88fb

8 files changed

+80
-33
lines changed

dist/undefined_AD-2.0.4.tar.gz

-21.6 KB
Binary file not shown.

dist/undefined_AD-2.1.0.tar.gz

21.5 KB
Binary file not shown.

htmlcov/index.html

Lines changed: 23 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = undefined_AD
3-
version = 2.0.4
3+
version = 2.1.0
44
author = cs107-undefined
55
author_email = [email protected]
66
description = Auto differetiation library

src/undefined_AD.egg-info/PKG-INFO

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Metadata-Version: 2.1
22
Name: undefined-AD
3-
Version: 2.0.4
3+
Version: 2.1.0
44
Summary: Auto differetiation library
55
Home-page: https://github.com/cs107-undefined/cs107-FinalProject
66
Author: cs107-undefined
@@ -17,9 +17,11 @@ License-File: LICENSE
1717

1818
# cs107-FinalProject
1919

20-
[![Build Status](https://app.travis-ci.com/cs107-undefined/cs107-FinalProject.svg?branch=milestone2)](https://app.travis-ci.com/cs107-undefined/cs107-FinalProject)
20+
[![Build Status](https://app.travis-ci.com/cs107-undefined/cs107-FinalProject.svg?branch=final_milestone)](https://app.travis-ci.com/cs107-undefined/cs107-FinalProject)
2121

22-
[![codecov](https://codecov.io/gh/cs107-undefined/cs107-FinalProject/branch/milestone2/graph/badge.svg?token=MWEZONI94C)](https://codecov.io/gh/cs107-undefined/cs107-FinalProject)
22+
[![codecov](https://codecov.io/gh/cs107-undefined/cs107-FinalProject/branch/final_milestone/graph/badge.svg?token=MWEZONI94C)](https://codecov.io/gh/cs107-undefined/cs107-FinalProject)
23+
24+
[![Documentation Status](https://readthedocs.org/projects/cs107-undefined/badge/?version=latest)](https://cs107-undefined.readthedocs.io/en/latest/?badge=latest)
2325

2426
[**DOCUMENTATION**](https://cs107-undefined.readthedocs.io/en/latest/)
2527

test/test_API.py

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,46 @@ def test_trace_with_incompatible_seeds(self):
6767
with self.assertRaises(AttributeError):
6868
trace(self.f2, seeds = np.array([[1,3,2],[1,3,2],[2,3,3]]), x=np.array(
6969
[[2, 3]]), y=np.array([[1, 2]]))
70-
#def test_trace_with_vector_inputs_with_seeds(self):
70+
71+
def test_trace_with_incompatible_seeds_reverse(self):
72+
with self.assertRaises(AttributeError):
73+
trace(self.f2, seeds = np.array([[1,3,2],[1,3,2],[2,3,3]]), mode = "reverse", x=np.array(
74+
[[2, 3]]), y=np.array([[1, 2]]))
75+
76+
def test_trace_with_scalar_inputs_seeds(self):
77+
with self.assertRaises(TypeError):
78+
trace(self.f1, seeds = np.array([[1,0]]), x=1)
79+
self.assertEqual(trace(self.f1, seeds = 2, x=1), (3,2))
80+
self.assertEqual(trace(self.f2, seeds = np.array([[1,0],[0,1]]), x=2, y=999)[1], [[1], [1]])
81+
with self.assertRaises(TypeError):
82+
trace(self.f2, seeds = 1, x=2, y=999)
83+
with self.assertRaises(TypeError):
84+
trace(self.f2, seeds = "seed", x=2, y=999)
85+
with self.assertRaises(TypeError):
86+
trace(self.f2, seeds = np.array([[1,0],[0,1]]), x="2", y=999)
87+
with self.assertRaises(AttributeError):
88+
trace(self.f2, seeds = np.array([[1],[0]]), x=2, y=999)
89+
90+
def test_trace_with_scalar_inputs_seeds_reverse(self):
91+
with self.assertRaises(TypeError):
92+
trace(self.f1, seeds = np.array([[1,0]]), mode='reverse', x=1)
93+
self.assertEqual(trace(self.f1, seeds = 2, mode='reverse', x=1), (3,2))
94+
self.assertEqual(trace(self.f2, seeds = np.array([[1,0],[0,1]]), mode='reverse', x=2, y=999)[1], [[1], [1]])
95+
with self.assertRaises(TypeError):
96+
trace(self.f2, seeds = 1, mode='reverse', x=2, y=999)
97+
with self.assertRaises(TypeError):
98+
trace(self.f2, seeds = "seed", mode='reverse', x=2, y=999)
99+
with self.assertRaises(TypeError):
100+
trace(self.f2, seeds = np.array([[1,0],[0,1]]), mode='reverse', x="2", y=999)
101+
with self.assertRaises(AttributeError):
102+
trace(self.f2, seeds = np.array([[1],[0]]), mode='reverse', x=2, y=999)
103+
104+
def test_trace_with_vector_inputs_seeds(self):
105+
self.assertEqual(trace(self.f2, seeds = np.array([[1,0],[0,1]]), x=np.array([[2, 3]]), y=np.array([[1, 2]]))[1], [[1, 1], [1, 1]])
106+
107+
def test_trace_with_vector_inputs_seeds_reverse(self):
108+
self.assertEqual(trace(self.f2, seeds = np.array([[1,0],[0,1]]), mode='reverse', x=np.array([[2, 3]]), y=np.array([[1, 2]]))[1], [[1, 1], [1, 1]])
109+
71110
def test_trace_with_different_moded(self):
72111
self.assertEqual(trace(self.f1, x=2), (4, 1))
73112
self.assertEqual(trace(self.f1, mode='forward', x=2), (4, 1))
@@ -111,10 +150,18 @@ def test_trace_multiple_vector_inputs(self):
111150
self.assertEqual(trace(self.f3, mode='reverse', x=np.array(
112151
[[2, 2]]), y=np.array([[4, 4]]))[1], [[2., 2.], [0.25, 0.25]])
113152

114-
def test_trace_single_vector_inputs(self):
153+
def test_trace_single_vector_input(self):
115154
self.assertEqual(trace(self.f1, x=np.array([[2, 2]]))[1], [[1, 1]])
155+
with self.assertRaises(TypeError):
156+
trace(self.f1, x=np.array([]))
116157

158+
def test_trace_non_lambda_function(self):
159+
with self.assertRaises(TypeError):
160+
trace("Function", x = 1)
117161

162+
def test_trace_vector_functions(self):
163+
self.assertEqual(trace([self.f2,self.f3], x = 2, y = 4)[1].tolist(), [[[1.0], [1.0]], [[2.0], [0.25]]])
164+
118165
def test_mixed_inputs(self):
119166
self.assertEqual(trace(self.f3, x=np.array([[2, 2]]), y=4)[
120167
0].tolist(), [[6, 6]])
@@ -125,7 +172,8 @@ def test_mixed_inputs(self):
125172
1], [[2., 2.], [0.25, 0.25]])
126173
self.assertEqual(trace(self.f3, mode='reverse', x=np.array([[2, 2]]), y=4)[
127174
1], [[2., 2.], [0.25, 0.25]])
128-
175+
self.assertEqual(trace(self.f3, mode='reverse', x=np.array([[2, 2]]), y=np.array([[4, 4]]))[
176+
1], [[2., 2.], [0.25, 0.25]])
129177

130178
if __name__ == "__main__":
131179
unittest.main()

test/test_graph_generator_operation.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,9 +381,6 @@ def test_ge(self):
381381
with self.assertRaises(TypeError):
382382
self.f25 >= "self.f19"
383383

384-
385-
386-
387384

388385
# this will help to run the unittest directly.
389386
if __name__ == "__main__":

0 commit comments

Comments
 (0)