| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import unittest | 5 import unittest |
| 6 | 6 |
| 7 from libs.math.functions import Function | 7 from libs.math.functions import Function |
| 8 from libs.math.functions import MemoizedFunction | 8 from libs.math.functions import MemoizedFunction |
| 9 | 9 |
| 10 | 10 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 """``MemoizedFunction._ClearMemos`` does actually clear the memos. | 51 """``MemoizedFunction._ClearMemos`` does actually clear the memos. |
| 52 | 52 |
| 53 That is, we call the underlying function once (to set the memo), | 53 That is, we call the underlying function once (to set the memo), |
| 54 then swap put the underlying function with a different one (to be | 54 then swap put the underlying function with a different one (to be |
| 55 sure we know whether the next ``__call__`` goes to the memos or to | 55 sure we know whether the next ``__call__`` goes to the memos or to |
| 56 the function), and finally clear the memos and check. | 56 the function), and finally clear the memos and check. |
| 57 """ | 57 """ |
| 58 f = MemoizedFunction(_F) | 58 f = MemoizedFunction(_F) |
| 59 f(5) | 59 f(5) |
| 60 f._f = _G | 60 f._f = _G |
| 61 f._ClearMemos() | 61 f.ClearMemos() |
| 62 self.assertEqual(_G(5), f(5)) | 62 self.assertEqual(_G(5), f(5)) |
| OLD | NEW |