-
-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add handle recursive expressions #25
Add handle recursive expressions #25
Conversation
We can't throw on a first recursion iteration, because expressions can contain conditions and we can exit recursion. Here is another test case to show exit from recursion. But this implementation throws. Instead of call chain we can just use try/catch to intercept |
I implemented the second option. Only I used Map instead of Array. |
test/unit.js
Outdated
const sheet = new Sheet(); | ||
sheet.cells['A1'] = 100; | ||
sheet.cells['B1'] = 2; | ||
sheet.cells['C1'] = '= A1 === 100 ? A1 * (A1 = 1, E1) : 5'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does assignment work in this case? A1 = 1
When I run this code, I don't see to change value in A1.
When I run this code, I don't see to change value in A1. But I see new A1 property in end of object.
<ref *1> Sheet {
data: Map(2) { 'A1' => 100, 'B1' => 2 },
expressions: Map(3) {
'C1' => [Function (anonymous)],
'D1' => [Function (anonymous)],
'E1' => [Function (anonymous)]
},
values: [Circular *1],
context: [Circular *1],
cells: [Circular *1],
callChain: Map(3) { 'E1' => 1, 'D1' => 1, 'C1' => 1 },
A1: 1
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure. But case above is don't work correctly.
So, I added test case which exit from recursive expression but I use Math.random instead of Assigment (A1 = 1) 51f9230
This reverts commit 5adc7cc.
const sheet = new Sheet(); | ||
sheet.cells['A1'] = 100; | ||
sheet.cells['B1'] = 2; | ||
sheet.cells['C1'] = '=Math.round(Math.random()) ? A1 * E1 : 5'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Math.random
is not stable for use in unit tests. Of course, it is a low probability, that you will get 100 "one"s results in a row, but still, one of 2^100 test runs may fail with message:
Exit from recursive expression use Math.random ........ 0/1
not ok fail
--- wanted
+++ found
-[null]
+{
+ "message": "Recursive expression error"
+ "name": "Error"
+ "stack": "Error: Recursive expression error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, ok, thanks
I used this test to show 'exit from recursive expression' (only math.random came to mind)
when somebody will say how assignment in expression is work to I fix previous test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use F1
as a counter, increment it each C1
cell calculation triggered and exit recursion after certain limit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use
F1
as a counter, increment it eachC1
cell calculation triggered and exit recursion after certain limit
How we can change cell's value? @tshemsedinov
I written about it above
sheet.cells['C1'] = '= A1 *E1'; | ||
sheet.cells['D1'] = '=C1+8'; | ||
sheet.cells['E1'] = '=D1/2'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sheet.cells['C1'] = '= A1 *E1'; | |
sheet.cells['D1'] = '=C1+8'; | |
sheet.cells['E1'] = '=D1/2'; | |
sheet.cells['C1'] = '= A1 * E1'; | |
sheet.cells['D1'] = '= C1 + 8'; | |
sheet.cells['E1'] = '= D1 / 2'; |
npm t
)npm run fmt
)Сloses #5