diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c88619..72c651b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Random mode modified - `filter_color` function modified - `filter_projection` function modified +- `is_same_data` function modified - `README.md` updated ## [0.6] - 2022-04-13 ### Added diff --git a/samila/functions.py b/samila/functions.py index f7bbe66..c4ef5cc 100644 --- a/samila/functions.py +++ b/samila/functions.py @@ -516,6 +516,8 @@ def is_same_data(data1, data2, precision=10**-5): :type precision: float :return: True if they are the same """ + if len(data1) != len(data2): + return False is_same = map(lambda x, y: abs(x - y) < precision, data1, data2) return all(is_same) diff --git a/test/function_test.py b/test/function_test.py index bb0dcaf..48ba874 100644 --- a/test/function_test.py +++ b/test/function_test.py @@ -9,6 +9,10 @@ True >>> is_same_data([1,1.1,1.2,1.3,1.4],[1,1.11,1.3,1.4,1.5]) False +>>> is_same_data(s,[1,1.1,1.2,1.3,1.4,1.5,1.6]) +False +>>> is_same_data(s,[]) +False >>> filter_color("yellow") 'yellow' >>> filter_color((0.2,0.3,0.4)) diff --git a/test/overall_test.py b/test/overall_test.py index 72221d6..1da3fc9 100644 --- a/test/overall_test.py +++ b/test/overall_test.py @@ -208,6 +208,22 @@ False >>> del(g) >>> del g_.data1 >>> del(g_) +>>> g1 = GenerativeImage() +>>> function1 = eval("lambda x, y:" + g1.function1_str) +>>> function2 = eval("lambda x, y:" + g1.function2_str) +>>> g2 = GenerativeImage(function1=function1, function2=function2) +>>> g1.generate(seed=22) +>>> g2.generate(seed=22) +>>> is_same_data(g1.data1, g2.data1) +True +>>> is_same_data(g1.data2, g2.data2) +True +>>> len(g1.data1) > 0 +True +>>> len(g1.data2) > 0 +True +>>> del(g1) +>>> del(g2) >>> os.remove("test.png") >>> os.remove("test2.png") >>> os.remove("data.json")