Something went wrong. Try again.
bayes for days
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273"""The growth table says what the log said, and nothing it did not."""
from __future__ import annotations
import unittest
from sds.loscache import phases, table, turns
# Three turns of deployment and two of round one's movement, in the bot's own# format. The totals are running, which is the thing the roll-up has to undo.LOG = """[sds-bot] unit 1 DEPLOYMENT round 0: heat 0 + buildup 0, capacity 30[sds-bot] los cache round 0 DEPLOYMENT: 100 lines, 0.01 MB est, 90% hit over 1000 asked, turn 2000ms[sds-bot] los cache round 0 DEPLOYMENT: 150 lines, 0.02 MB est, 92% hit over 2000 asked, turn 1800ms[sds-bot] los cache round 0 DEPLOYMENT: 170 lines, 0.02 MB est, 94% hit over 3000 asked, turn 1500ms[sds-bot] planning failed: nothing here matches[sds-bot] los cache round 1 MOVEMENT: 200 lines, 0.03 MB est, 95% hit over 5000 asked, turn 40ms[sds-bot] los cache round 1 MOVEMENT: 210 lines, 0.03 MB est, 96% hit over 6000 asked, turn 35ms"""
class GrowthTable(unittest.TestCase): def test_reads_only_its_own_lines(self): played = turns(LOG) self.assertEqual(len(played), 5) self.assertEqual(played[0].round, 0) self.assertEqual(played[0].phase, "DEPLOYMENT") self.assertEqual(played[-1].lines, 210)
def test_a_turns_own_share_is_the_difference(self): rolled = phases(turns(LOG)) self.assertEqual([(p.round, p.phase) for p in rolled], [(0, "DEPLOYMENT"), (1, "MOVEMENT")]) deployment, movement = rolled self.assertEqual(deployment.turns, 3) # 3000 asked over the phase, 170 of them misses: every miss inserts one # entry and no hit does. self.assertEqual(deployment.asked, 3000) self.assertEqual(deployment.added, 170) self.assertEqual(deployment.hits, 3000 - 170) self.assertEqual(deployment.millis, 5300) # Movement starts from the cache deployment left behind, which is the # whole point of sharing it: 2000 more asked, 40 more lines. self.assertEqual(movement.asked, 3000) self.assertEqual(movement.added, 40) self.assertEqual(movement.lines, 210)
def test_the_table_carries_the_last_reading(self): rendered = table(phases(turns(LOG))) self.assertIn("deployment", rendered) self.assertIn("movement", rendered) # The final row is the match, and the size is the last one printed # rather than a sum of per-phase sizes. self.assertTrue(rendered.splitlines()[-1].strip().startswith("all")) self.assertIn("0.03", rendered.splitlines()[-1])
def test_a_log_with_none_of_its_lines_rolls_up_to_nothing(self): self.assertEqual(turns("[sds-bot] unit 3: nothing to see"), []) self.assertEqual(phases([]), [])
class CountersThatWentBackwards(unittest.TestCase): """A cleared cache, or two matches in one file, must not read as negative."""
CLEARED = """[sds-bot] los cache round 1 MOVEMENT: 900 lines, 0.11 MB est, 98% hit over 9000 asked, turn 50ms[sds-bot] los cache round 2 MOVEMENT: 400 lines, 0.05 MB est, 90% hit over 4000 asked, turn 60ms"""
def test_the_share_is_the_new_reading(self): rolled = phases(turns(self.CLEARED)) self.assertEqual([p.asked for p in rolled], [9000, 4000]) self.assertEqual([p.added for p in rolled], [900, 400])