Skip to content

Commit

Permalink
Add extra tests
Browse files Browse the repository at this point in the history
  • Loading branch information
XinranTang committed Dec 10, 2021
1 parent f088d13 commit 3ab88fb
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 33 deletions.
Binary file removed dist/undefined_AD-2.0.4.tar.gz
Binary file not shown.
Binary file not shown.
Binary file added dist/undefined_AD-2.1.0.tar.gz
Binary file not shown.
46 changes: 23 additions & 23 deletions htmlcov/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = undefined_AD
version = 2.0.4
version = 2.1.0
author = cs107-undefined
author_email = [email protected]
description = Auto differetiation library
Expand Down
8 changes: 5 additions & 3 deletions src/undefined_AD.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: undefined-AD
Version: 2.0.4
Version: 2.1.0
Summary: Auto differetiation library
Home-page: https://github.com/cs107-undefined/cs107-FinalProject
Author: cs107-undefined
Expand All @@ -17,9 +17,11 @@ License-File: LICENSE

# cs107-FinalProject

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

[![codecov](https://codecov.io/gh/cs107-undefined/cs107-FinalProject/branch/milestone2/graph/badge.svg?token=MWEZONI94C)](https://codecov.io/gh/cs107-undefined/cs107-FinalProject)
[![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)

[![Documentation Status](https://readthedocs.org/projects/cs107-undefined/badge/?version=latest)](https://cs107-undefined.readthedocs.io/en/latest/?badge=latest)

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

Expand Down
54 changes: 51 additions & 3 deletions test/test_API.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,46 @@ def test_trace_with_incompatible_seeds(self):
with self.assertRaises(AttributeError):
trace(self.f2, seeds = np.array([[1,3,2],[1,3,2],[2,3,3]]), x=np.array(
[[2, 3]]), y=np.array([[1, 2]]))
#def test_trace_with_vector_inputs_with_seeds(self):

def test_trace_with_incompatible_seeds_reverse(self):
with self.assertRaises(AttributeError):
trace(self.f2, seeds = np.array([[1,3,2],[1,3,2],[2,3,3]]), mode = "reverse", x=np.array(
[[2, 3]]), y=np.array([[1, 2]]))

def test_trace_with_scalar_inputs_seeds(self):
with self.assertRaises(TypeError):
trace(self.f1, seeds = np.array([[1,0]]), x=1)
self.assertEqual(trace(self.f1, seeds = 2, x=1), (3,2))
self.assertEqual(trace(self.f2, seeds = np.array([[1,0],[0,1]]), x=2, y=999)[1], [[1], [1]])
with self.assertRaises(TypeError):
trace(self.f2, seeds = 1, x=2, y=999)
with self.assertRaises(TypeError):
trace(self.f2, seeds = "seed", x=2, y=999)
with self.assertRaises(TypeError):
trace(self.f2, seeds = np.array([[1,0],[0,1]]), x="2", y=999)
with self.assertRaises(AttributeError):
trace(self.f2, seeds = np.array([[1],[0]]), x=2, y=999)

def test_trace_with_scalar_inputs_seeds_reverse(self):
with self.assertRaises(TypeError):
trace(self.f1, seeds = np.array([[1,0]]), mode='reverse', x=1)
self.assertEqual(trace(self.f1, seeds = 2, mode='reverse', x=1), (3,2))
self.assertEqual(trace(self.f2, seeds = np.array([[1,0],[0,1]]), mode='reverse', x=2, y=999)[1], [[1], [1]])
with self.assertRaises(TypeError):
trace(self.f2, seeds = 1, mode='reverse', x=2, y=999)
with self.assertRaises(TypeError):
trace(self.f2, seeds = "seed", mode='reverse', x=2, y=999)
with self.assertRaises(TypeError):
trace(self.f2, seeds = np.array([[1,0],[0,1]]), mode='reverse', x="2", y=999)
with self.assertRaises(AttributeError):
trace(self.f2, seeds = np.array([[1],[0]]), mode='reverse', x=2, y=999)

def test_trace_with_vector_inputs_seeds(self):
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]])

def test_trace_with_vector_inputs_seeds_reverse(self):
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]])

def test_trace_with_different_moded(self):
self.assertEqual(trace(self.f1, x=2), (4, 1))
self.assertEqual(trace(self.f1, mode='forward', x=2), (4, 1))
Expand Down Expand Up @@ -111,10 +150,18 @@ def test_trace_multiple_vector_inputs(self):
self.assertEqual(trace(self.f3, mode='reverse', x=np.array(
[[2, 2]]), y=np.array([[4, 4]]))[1], [[2., 2.], [0.25, 0.25]])

def test_trace_single_vector_inputs(self):
def test_trace_single_vector_input(self):
self.assertEqual(trace(self.f1, x=np.array([[2, 2]]))[1], [[1, 1]])
with self.assertRaises(TypeError):
trace(self.f1, x=np.array([]))

def test_trace_non_lambda_function(self):
with self.assertRaises(TypeError):
trace("Function", x = 1)

def test_trace_vector_functions(self):
self.assertEqual(trace([self.f2,self.f3], x = 2, y = 4)[1].tolist(), [[[1.0], [1.0]], [[2.0], [0.25]]])

def test_mixed_inputs(self):
self.assertEqual(trace(self.f3, x=np.array([[2, 2]]), y=4)[
0].tolist(), [[6, 6]])
Expand All @@ -125,7 +172,8 @@ def test_mixed_inputs(self):
1], [[2., 2.], [0.25, 0.25]])
self.assertEqual(trace(self.f3, mode='reverse', x=np.array([[2, 2]]), y=4)[
1], [[2., 2.], [0.25, 0.25]])

self.assertEqual(trace(self.f3, mode='reverse', x=np.array([[2, 2]]), y=np.array([[4, 4]]))[
1], [[2., 2.], [0.25, 0.25]])

if __name__ == "__main__":
unittest.main()
3 changes: 0 additions & 3 deletions test/test_graph_generator_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,6 @@ def test_ge(self):
with self.assertRaises(TypeError):
self.f25 >= "self.f19"





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

0 comments on commit 3ab88fb

Please sign in to comment.