From e5098a3ff9948427bd8098a9f74f69265b2cb2d8 Mon Sep 17 00:00:00 2001 From: Noiredd Date: Mon, 27 Apr 2020 21:11:02 +0200 Subject: [PATCH] test suite: database update (removal) tests 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. --- test/README.md | 11 +++++- test/test_database.py | 81 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 90 insertions(+), 2 deletions(-) diff --git a/test/README.md b/test/README.md index 104ac38..f0931d2 100644 --- a/test/README.md +++ b/test/README.md @@ -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. @@ -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. diff --git a/test/test_database.py b/test/test_database.py index eafeaf5..83debd1 100644 --- a/test/test_database.py +++ b/test/test_database.py @@ -255,7 +255,7 @@ 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) @@ -263,6 +263,8 @@ def __test_body(self, scenario): 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]) @@ -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