I have tried to solve Task 4 of Coordination Transformation but always get failed in Test 15. It says the function “should not call the memoized function if the input is the same”. Why it expected to return value [1, 1] and why the argument is fakeTransform() not translate2d() or scale2d()?
Why it expected to return value [1, 1] and why the argument is fakeTransform() not translate2d() or scale2d()?
In Test 15, the test is checking whether you do NOT call the function again if the inputs are the same? To effectively test this, fakeTransform() is a mock function that is passed to your function which returns [1,1] when you call it first time, but returns false when you call it again. This fake function essentially verifies that you do NOT call your calculation function - since we need a special logic to check whether the function is called more than once, we can’t use the usual translate2d or scale2d which do NOT have this logic.
To make this test pass, plz store the input and the result when the function is called first time. Then in the 2nd call, check the input to see if they are the same - if yes, do NOT call the function again, but pass the stored result back. If the input is different, you can call the function again to cache the new result.
It’s work. Thanks for helping me out.