From a4b0fac121b19a3e44104b89af50d33979095b6c Mon Sep 17 00:00:00 2001 From: Mirosław Sztorc Date: Wed, 6 Jan 2021 01:06:04 +0100 Subject: Cache-control improvements (#81) * cache-control improvements * Update src/NXP/MathExecutor.php yeah, you're right. Co-authored-by: Alexander Kiryukhin * Update MathExecutor.php braces qfix * Update MathExecutor.php Co-authored-by: Alexander Kiryukhin --- tests/MathTest.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'tests') diff --git a/tests/MathTest.php b/tests/MathTest.php index 1e5da5a..a5061ad 100644 --- a/tests/MathTest.php +++ b/tests/MathTest.php @@ -589,4 +589,28 @@ class MathTest extends TestCase ]; } + public function testCache() + { + $calculator = new MathExecutor(); + $this->assertEquals(256, $calculator->execute('2 ^ 8')); // second arg $cache is true by default + + $this->assertIsArray($calculator->getCache()); + $this->assertEquals(1, count($calculator->getCache())); + + $this->assertEquals(512, $calculator->execute('2 ^ 9', true)); + $this->assertEquals(2, count($calculator->getCache())); + + $this->assertEquals(1024, $calculator->execute('2 ^ 10', false)); + $this->assertEquals(2, count($calculator->getCache())); + + $calculator->clearCache(); + $this->assertIsArray($calculator->getCache()); + $this->assertEquals(0, count($calculator->getCache())); + + $this->assertEquals(2048, $calculator->execute('2 ^ 11', false)); + $this->assertEquals(0, count($calculator->getCache())); + + + } + } \ No newline at end of file -- cgit v1.2.3