Skip to content

Commit

Permalink
Use FloatField instead of CharField
Browse files Browse the repository at this point in the history
Signed-off-by: Jono Yang <[email protected]>
  • Loading branch information
JonoYang committed Oct 11, 2023
1 parent 5784bf8 commit b38be78
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion matchcode/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from rest_framework.decorators import action
from rest_framework.response import Response
from rest_framework.serializers import CharField
from rest_framework.serializers import FloatField
from rest_framework.serializers import HyperlinkedRelatedField
from rest_framework.serializers import ModelSerializer
from rest_framework.serializers import ReadOnlyField
Expand Down Expand Up @@ -92,7 +93,7 @@ class BaseDirectoryIndexMatchSerializer(Serializer):
lookup_field='uuid',
read_only=True
)
similarity_score = CharField()
similarity_score = FloatField()


class CharMultipleWidget(widgets.TextInput):
Expand Down
8 changes: 4 additions & 4 deletions matchcode/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def test_api_approximate_directory_content_index_match_close_match(self):
self.assertEqual(expected_matched_fingerprint, result['matched_fingerprint'])
expected_package = 'http://testserver' + reverse('api:package-detail', args=[self.test_package1.uuid])
self.assertEqual(expected_package, result['package'])
self.assertEqual('0.9453125', result['similarity_score'])
self.assertEqual(0.9453125, result['similarity_score'])

def test_api_approximate_directory_structure_index_match_close_match(self):
# This test fingerprint has a hamming distance of 7 from the expected fingerprint
Expand All @@ -134,7 +134,7 @@ def test_api_approximate_directory_structure_index_match_close_match(self):
self.assertEqual(expected_matched_fingerprint, result['matched_fingerprint'])
expected_package = 'http://testserver' + reverse('api:package-detail', args=[self.test_package2.uuid])
self.assertEqual(expected_package, result['package'])
self.assertEqual('0.9453125', result['similarity_score'])
self.assertEqual(0.9453125, result['similarity_score'])

def test_api_approximate_directory_content_index_match(self):
test_fingerprint = '00000007af7d63765c78fa516b5353f5ffa7df45'
Expand All @@ -149,7 +149,7 @@ def test_api_approximate_directory_content_index_match(self):
self.assertEqual(test_fingerprint, result['matched_fingerprint'])
expected_package = 'http://testserver' + reverse('api:package-detail', args=[self.test_package1.uuid])
self.assertEqual(expected_package, result['package'])
self.assertEqual('1.0', result['similarity_score'])
self.assertEqual(1.0, result['similarity_score'])

def test_api_approximate_directory_structure_index_match(self):
test_fingerprint = '00000004d10982208810240820080a6a3e852486'
Expand All @@ -164,4 +164,4 @@ def test_api_approximate_directory_structure_index_match(self):
self.assertEqual(test_fingerprint, result['matched_fingerprint'])
expected_package = 'http://testserver' + reverse('api:package-detail', args=[self.test_package2.uuid])
self.assertEqual(expected_package, result['package'])
self.assertEqual('1.0', result['similarity_score'])
self.assertEqual(1.0, result['similarity_score'])

0 comments on commit b38be78

Please sign in to comment.