Skip to content

Commit

Permalink
test suite: database update (removal) tests
Browse files Browse the repository at this point in the history
Note that due to the update algorithm available at the time it is expected to
see 6 out of the 15 tests FAILING and 1 other being SKIPPED.
  • Loading branch information
Noiredd committed Apr 27, 2020
1 parent 6fe9d55 commit e5098a3
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 2 deletions.
11 changes: 10 additions & 1 deletion test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,16 @@ as the `__ne__` operator, so all comparisons during the testing are done this wa
*Note*: `Database` is only tested for the `Movie` item type,
as the algorithm is abstract with respect to the item type.

#### Basic tests

The first two tests - `TestDatabaseCreation` and `TestDatabaseSerialization`
are responsible for the most basic functionality of the `Database`.
The creation test is of a particular importance here,
as if that one fails, pretty much everything else after that will also fail.

#### Update tests

Database update tests are performed by loading a reference `Database` first
Database update tests (`TestDatabaseUpdates`) are performed by loading a reference `Database` first
(this utilizes assets cached in API tests).
Each test simulates a situation in which this reference `Database` is the desired outcome,
and the "current" state is generated dynamically according to some scenario.
Expand All @@ -68,4 +75,6 @@ and constructs a new `Database`, simulating a previous state (as if "undoing" an
During the test, this "undone" object attempts to update itself to the reference state.
Results are compared using the aforementioned `DatabaseDifference`.

Note that currently all removal tests fail
due to the removal detection not being implemented in the Database update algorithm.

81 changes: 80 additions & 1 deletion test/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,16 @@ def makeModifiedDatabase(self, scenario:UpdateScenario):
return new_db

def __test_body(self, scenario):
"""since they all look the same..."""
"""Since they all look the same..."""
alter_db = self.makeModifiedDatabase(scenario)
# Make sure the databases are actually different!
self.assertNotEqual(alter_db, self.orig_db)
# Call update and check difference
alter_db.softUpdate()
self.assertEqual(alter_db, self.orig_db)

# Addition tests

def test_singleAddition(self):
"""Add a single missing item."""
scenario = UpdateScenario(removals=[0])
Expand All @@ -273,11 +275,88 @@ def test_simpleAddition(self):
scenario = UpdateScenario(removals=[0, 1, 2])
self.__test_body(scenario)

def test_randomAddition(self):
"""Add an item missing from somewhere on the first page."""
scenario = UpdateScenario(removals=[4])
self.__test_body(scenario)

def test_nonContinuousAddition(self):
"""Add a few items non-continuously missing from the first page."""
scenario = UpdateScenario(removals=[0, 1, 2, 3, 6])
self.__test_body(scenario)

def test_multipageAddition(self):
"""Add a few items non-continuously missing from multiple pages."""
scenario = UpdateScenario(removals=[0, 1, 2, 16, 30, 32])
self.__test_body(scenario)

# Removal tests

def test_singleRemoval(self):
"""Remove a single item from the first page."""
scenario = UpdateScenario(additions=[(0, 666)])
self.__test_body(scenario)

def test_simpleRemoval(self):
"""Remove a few items from the first page."""
scenario = UpdateScenario(additions=[(0, 666), (1, 4270)])
self.__test_body(scenario)

def test_randomRemoval(self):
"""Remove an item from somewhere on the first page."""
scenario = UpdateScenario(additions=[(4, 420)])
self.__test_body(scenario)

def test_nonContinuousRemoval(self):
"""Remove a few items non-continuously from the first page."""
scenario = UpdateScenario(
additions=[(0, 666), (1, 4270), (2, 2137), (5, 61504)]
)
self.__test_body(scenario)

def test_multipageRemoval(self):
"""Remove a few items non-continuously from multiple pages."""
scenario = UpdateScenario(
additions=[(3, 666), (4, 4270), (15, 2137), (35, 61504)]
)
self.__test_body(scenario)

# Other tests

def test_complexAdditionRemoval(self):
"""Add and remove a few items at once, but only from the first page."""
scenario = UpdateScenario(
removals=[0, 1, 2, 9, 13],
additions=[(3, 1991), (4, 37132)]
)

@unittest.skip('Relevant feature not implemented yet.')
def test_difficultAdditionRemoval(self):
"""Add and remove a few items at once from multiple pages.
This test is extremely difficult because it is impossible to recognize such
scenario in real usage (online), by looking at getNumOf alone. That number
only shows the total balance of added/removed items. If that balance evens
out on any page further than 1st (like in the case of removing some items
and adding the same number of items), it is impossible to spot to any fast
and simple algorithm (i.e. one that does not deeply inspect all pages).
"""
scenario = UpdateScenario(
removals=[0, 1, 2, 9, 33],
additions=[(3, 1991), (34, 37132)]
)

def test_hardUpdate(self):
"""Make "random" removals and additions, then hard update."""
scenario = UpdateScenario(
removals=[1, 5, 6, 7, 40],
additions=[(0, 666), (13, 667)]
)
alter_db = self.makeModifiedDatabase(scenario)
self.assertNotEqual(alter_db, self.orig_db)
alter_db.hardUpdate()
self.assertEqual(alter_db, self.orig_db)


if __name__ == "__main__":
database.Database.__ne__ = DatabaseDifference.compute
Expand Down

0 comments on commit e5098a3

Please sign in to comment.