Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix strategy definition #383

Merged
merged 2 commits into from
Aug 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions clkhash/schemas/v3.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,20 +158,26 @@
[
{
"required": ["bitsPerToken"],
"bitsPerToken": {
"type": "integer",
"minimum": 1,
"default": 20,
"description": "every token gets inserted into the Bloom filter exactly 'bitsPerToken' times."
"additionalProperties": false,
"properties": {
"bitsPerToken": {
"type": "integer",
"minimum": 1,
"default": 20,
"description": "every token gets inserted into the Bloom filter exactly 'bitsPerToken' times."
}
}
},
{
"required": ["bitsPerFeature"],
"bitsPerFeature": {
"type": "integer",
"minimum": 1,
"default": 200,
"description": "token get inserted into the Bloom filter a variable number of times such that the insertions of the tokens corresponding to one feature add up to 'bitsPerFeature'."
"additionalProperties": false,
"properties": {
"bitsPerFeature": {
"type": "integer",
"minimum": 1,
"default": 200,
"description": "token get inserted into the Bloom filter a variable number of times such that the insertions of the tokens corresponding to one feature add up to 'bitsPerFeature'."
}
}
}
]},
Expand Down
18 changes: 16 additions & 2 deletions tests/test_schema.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@

import io
import json
import os
import pytest
import unittest
from jsonschema import ValidationError

from clkhash import schema
from clkhash.schema import SchemaError, MasterSchemaError
Expand Down Expand Up @@ -244,3 +243,18 @@ def test_issue_111(self):

# This fails in #111. Now it shouldn't.
schema.from_json_dict(schema_dict)

def test_illegal_strategy(self):
gschema = _schema_dict(TEST_DATA_DIRECTORY, GOOD_SCHEMA_V3_PATH)
for bad_value in 'boom', -1, 4.5:
gschema['features'][1]['hashing']['strategy']['bitsPerFeature'] = bad_value
with pytest.raises(SchemaError):
schema.from_json_dict(gschema)
for bad_value in 'four', -4, 4.0:
gschema['features'][2]['hashing']['strategy']['bitsPerToken'] = bad_value
with pytest.raises(SchemaError):
schema.from_json_dict(gschema)
# we cannot define both at the same time
gschema['features'][1]['hashing']['strategy']['bitsPerToken'] = 12
with pytest.raises(SchemaError):
schema.from_json_dict(gschema)