2020-06-20 14:53:44 +02:00
|
|
|
import pytest
|
2020-02-22 14:07:24 +01:00
|
|
|
|
|
|
|
from util.algorithm import *
|
|
|
|
|
2020-06-20 14:53:44 +02:00
|
|
|
@pytest.fixture
|
|
|
|
def someData():
|
|
|
|
return {"a": 100, "b": 200, "c": [1, 2, 3]}
|
2020-05-03 11:15:52 +02:00
|
|
|
|
2020-06-20 14:53:44 +02:00
|
|
|
@pytest.fixture
|
|
|
|
def differentData():
|
|
|
|
return {"x": 20, "y": "bla", "z": ["a", "b"]}
|
2020-02-22 14:07:24 +01:00
|
|
|
|
2020-06-20 14:53:44 +02:00
|
|
|
@pytest.fixture
|
|
|
|
def moreData():
|
|
|
|
return {"n": 100}
|
2020-02-22 14:07:24 +01:00
|
|
|
|
2020-06-20 14:53:44 +02:00
|
|
|
@pytest.fixture
|
|
|
|
def overlapData():
|
|
|
|
return {"a": 200, "c": [1, 2, 4]}
|
2020-02-22 14:07:24 +01:00
|
|
|
|
2020-06-20 14:53:44 +02:00
|
|
|
def test_merge_with_empty(someData):
|
|
|
|
assert merge(someData, {}) == someData
|
|
|
|
assert merge(someData, None) == None
|
2020-02-22 14:07:24 +01:00
|
|
|
|
2020-06-20 14:53:44 +02:00
|
|
|
def test_merge_no_overwrite(someData, differentData):
|
|
|
|
result = merge(someData, differentData)
|
|
|
|
for k in someData:
|
|
|
|
assert someData[k] == result[k]
|
|
|
|
for k in self.differentData:
|
|
|
|
assert differentData[k] == result[k]
|
|
|
|
|
|
|
|
def test_merge_multiple(someData, differentData, moreData):
|
|
|
|
result = merge(someData, differentData, moreData)
|
|
|
|
for k in someData:
|
|
|
|
assert someData[k] == result[k]
|
|
|
|
for k in differentData:
|
|
|
|
assert differentData[k] == result[k]
|
|
|
|
for k in moreData:
|
|
|
|
assert moreData[k] == result[k]
|
|
|
|
|
|
|
|
def merge_overlap(someData, overlapData):
|
|
|
|
result = merge(someData, overlapData)
|
|
|
|
for k in someData:
|
2020-02-22 14:07:24 +01:00
|
|
|
if not k in self.overlapData:
|
2020-06-20 14:53:44 +02:00
|
|
|
assert someData[k] == result[k]
|
2020-02-22 14:07:24 +01:00
|
|
|
for k in self.overlapData:
|
2020-06-20 14:53:44 +02:00
|
|
|
assert overlapData[k] == result[k]
|
2020-02-22 14:07:24 +01:00
|
|
|
|
2020-05-03 11:15:52 +02:00
|
|
|
|
2020-02-22 14:07:24 +01:00
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|