Re: [Rails] Given an expression: 2 + ( ( 4 + 6 ) * (9 - 2) - 5 - 1) + 1 Write a program to calculate
Ruby on Rails
Monday, January 5, 2015
Without an "x" in that expression I would argue that you don't need (and shouldn't have) a unit test.
Now, if you add an "x" to that expression, then your unit test becomes "Given value of X is ___, the result is ___" which makes a certain kind of sense.
But without an "x", all you're testing is Ruby's ability to parse, and C's ability to do math, which is certainly not within the scope of your use case or domain.
Also I would argue that mathematically the part of the expression that reads (9 - 2) - 5 - 1 is ambiguous in terms of algebra since you need to know if the minus operation is "left order precedence" or "right order precedence". Personally I don't have time in my workday to remember that specific nuance of Ruby's implementation of algebra and if this were a Junior dev submitting a pull request I would make him or her add parenthesis to eliminate that confusion.
Just my 2¢ on your post.
-Jason
On Jan 5, 2015, at 8:35 AM, Qiangsheng Wang <wangqsh999@gmail.com> wrote:Given an expression: 2 + ( ( 4 + 6 ) * (9 - 2) - 5 - 1) + 11. Write a program calculate the given expression2. Do not simply use "eval" directly3. Need unit testBouns:2 + ( ( 4 + 6 ) * sqrt(5) + 3) / 2 + 1Here is my code, who can improve this for me? Thank you!Here is test code.--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/feeb4542-9acb-48d1-96e3-445e8a8ae9af%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
----
Jason Fleetwood-Boldt
All material © Jason Fleetwood-Boldt 2014. Public conversations may be turned into blog posts (original poster information will be made anonymous). Email jason@datatravels.com with questions/concerns about this.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment