Skip to content

Commit

Permalink
Fix strategy definition (#383)
Browse files Browse the repository at this point in the history
* test correct validation of strategy

* fixed strategy definition
  • Loading branch information
wilko77 authored Aug 30, 2020
1 parent a8f7a7d commit 9c9afcf
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
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)

0 comments on commit 9c9afcf

Please sign in to comment.