diff --git a/neo4django/tests/nodequeryset_tests.py b/neo4django/tests/nodequeryset_tests.py index 752d2cf..7289145 100644 --- a/neo4django/tests/nodequeryset_tests.py +++ b/neo4django/tests/nodequeryset_tests.py @@ -363,6 +363,36 @@ def test_filter_range(): all_between_s_u = Person.objects.filter(name__range=('S','U')) assert len(all_between_s_u) >= 1, "There's at least one 'T' name!" + +@with_setup(None, teardown) +def test_filter_float_range(): + import random + + epsilon = 0.001 + ages = [] + while len(ages) < 5: + r = random.uniform(-5.0, 5.0) + if not(any(r > i - epsilon and r < i + epsilon for i in ages)): + ages.append(r) + + class FloatAgedPerson(models.NodeModel): + age = models.FloatProperty() + indexed_age = models.FloatProperty(indexed=True) + + for a in ages: + FloatAgedPerson.objects.create(age=a, indexed_age=a) + + # unindexed range queries + for a in ages: + eq_(1, len(FloatAgedPerson.objects.filter( + age__range=[a - epsilon,a + epsilon]))) + + # indexed range queries + for a in ages: + eq_(1, len(list(FloatAgedPerson.objects.filter( + indexed_age__range=[a - epsilon, a + epsilon])))) + + @with_setup(None, teardown) def test_filter_date_range(): class Lifetime(models.NodeModel): diff --git a/neo4django/tests/property_tests.py b/neo4django/tests/property_tests.py index 77c2ae2..2963c66 100644 --- a/neo4django/tests/property_tests.py +++ b/neo4django/tests/property_tests.py @@ -1,4 +1,4 @@ -from nose.tools import eq_, with_setup +from nose.tools import eq_, with_setup, assert_almost_equal from django.core.exceptions import ValidationError import datetime @@ -75,7 +75,21 @@ def try_int(integer): for i in [0,1,-1,28,neo4django.db.models.properties.MAX_INT,neo4django.db.models.properties.MIN_INT]: try_int(i) + +@with_setup(None, teardown) +def test_float(): + class FloatPerson(models.NodeModel): + age = models.FloatProperty() + age_indexed = models.FloatProperty(indexed=True) + + vals = [0.0, -1.0, 1.0, 12345.6789, 98766.123123, -1232375.4234] + + # check the values + for f in vals: + node = FloatPerson.objects.create(age=f, age_indexed=f) + assert_almost_equal(f, FloatPerson.objects.get(id=node.id).age) + def test_date_constructor(): class DateNode(models.NodeModel): date = models.DateProperty() @@ -281,6 +295,26 @@ class IntArrayNode(models.NodeModel): else: raise AssertionError('tuples of strs should not validate') +@with_setup(None, teardown) +def test_float_array_property(): + """Tests that FloatArrayProperty validates, saves and returns properly.""" + class FloatArrayNode(models.NodeModel): + vals = models.FloatArrayProperty() + + vals = (1,2.1234,3.0,-1.0) + n1 = FloatArrayNode(vals = vals) + eq_(n1.vals, vals) + n1.save() + eq_(n1.vals, vals) + + try: + n2 = IntArrayNode(vals = ('1.12','2.0','-3')) + n2.save() + except ValidationError: + pass + else: + raise AssertionError('tuples of strs should not validate') + def test_str_array_property_validator(): """Tests that StringArrayProperty validates properly.""" class StrArrayNode(models.NodeModel): diff --git a/reg_settings.py b/reg_settings.py index f2c1e92..d15cd12 100644 --- a/reg_settings.py +++ b/reg_settings.py @@ -184,7 +184,10 @@ 'test_create_with_id', 'test_relationship_get_by_id', 'test_update', - 'test_relationship_filter_many_to_many'] + 'test_relationship_filter_many_to_many', + 'test_float', + 'test_filter_float_range', + 'test_float_array_property'] should_fail=[ 'test_dates', 'test_relationship_model', @@ -196,4 +199,7 @@ 'test_relationship_models', 'test_typenode_transactionality', 'test_autoproperty_transactionality', - 'test_relationship_filter_many_to_many'] + 'test_relationship_filter_many_to_many', + 'test_float', + 'test_filter_float_range', + 'test_float_array_property']