Note expected accuracy in space-age description#880
Conversation
|
|
||
| So if you were told someone were 1,000,000,000 seconds old, you should | ||
| be able to say that they're 31 Earth-years old. | ||
| be able to say that they're 31.69 Earth-years old. Round all ages to |
There was a problem hiding this comment.
I'll trust that your math is correct. 😉
There was a problem hiding this comment.
I pulled this from the canonical data, thereby passing the buck 😄
|
Sure the README should impose the **requirement** to round the result,
rather than to leave it unrounded?
|
|
The canonical data already imposed that requirement. |
|
I do not think the fact that the canonical data was rounded to two places
implies that student solutions are expected to round to two places. My
impression may be biased by the tracks that I have seen implement this
exercise
|
|
It seems that explicit rounding would make life much easier for tracks with generated tests. Are there other cases where we use some approximate representation of the actual value you would expect to be computed? |
|
Here a te souce of my bias
* Ruby exercism/ruby#103
exercism/ruby#104
* C# exercism/csharp#19
But, there are possibly other tracks that do not. I cannot provide them
right now.
Are there other cases where we use some approximate representation of the actual value you would expect to be computed?
I thik space age is one of two of our exercis with foats. te othr is
triangle, #798,
but the expectatio is a boolean so no approximation.
I suppose if there ae exercises thatuseproperty-based testing (diamond,
dminoes) that iskind of in the same vein but not really?
|
|
From one of those threads you linked:
That's the problem solved here, no? |
|
> It's not a problem if the results should be rounded to two decimal places but I think it should explicitly say that in the problem.
That's the problem solved here, no?
Exactly the question I am asking: whether it is OK to explicitly require
rounding and say so in the README.
My immediate reaction is "This seems like an arbitrary extra requirement to
tack on to the problem. Why not just let students leave the answers
unrounded?", and therefore I originally thought that I would oppose adding
the requirement.
But I don't have a logical reason that the extra requirement is *bad*. One
may even consider it **good** to expose students to how to round.
Whether we want rounding or not, I think we run into the same problems
regarding having to compare two floating point numbers, so I think those
considerations don't affect this decision either way, but let me know if I
am wrong, especially if there is a solution that produces a false negative
or a false positive.
|
|
I think I see. There are essentially two main options that would make sense for generated tests:
This PR moved us to option 1; you're suggesting that we may want to consider something like option 2 based on the concepts it will introduce (assertions with tolerances, vs explicit rounding in option 1)? |
|
I apologize for merging too soon. This is an interesting discussion. |
No worries, and agreed r.e. the discussion :) Easy to adjust once a conclusion is reached, if required. |
|
provide the rounded values to match exactly in the data;
I read that it is inadvisable to compare floating-point numbers for
equality, but I have no firsthand experience backing up this statement
(whether in the context of this exercise or other contexts) nor do I
remember what exactly gave me this impression.
So if the option to expect+mention rounding is taken, tolerances *may*
still be necessary. I do not know for sure, so I hope anyone who knows more
than I do can help.
provide both rounded values to match and a rounding tolerance in the data.
Interesting add-on that I hadn't thought of before! Adding a tolerance has
the advantage of being a reminder to readers (human or computer) of the
file.
I would say the driver of the decision of whether to expect+mention
rounding should be whether it makes sense to ask student implementations to
round. Pro: Helps students learn how to round in the implementation
language. Con: Seems "arbitrary", meaning there doesn't seem a good reason
other than "because the specification says so". Based on that, I would say
not to expect+mention rounding, with the strength of my opinion being 1/10.
Whether to test with tolerances I think is driven by whether (in
conjunction with whether we decide to round) it may cause false positives
or false negatives. I don't know to what precision we would write the
values in the JSON file if we don't expect rounding (so we would probably
need tolerances). If we do expect rounding I don't see a reason it matters
whether we have tolerances but given what I read I could be wrong.
|
|
I do see that there is a factor in the decision that I had been
disregarding by not mentioning it at all: The effect on test
generators. This factor is good to consider, though I think secondary
in relation to "whether it may cause false positives or false
negatives"
|
This is an excellent point; given this, tracks need to decide on (or use a canonical) equality tolerance for both options I outlined, in which case, it might be better for the README to instead state this tolerance explicitly? |
|
it might be better for the README to instead state this tolerance explicitly?
That seems to make sense. May be a good time to link to any resources we
can find on why checks for floating point equality are done that way.
(There was talk in #798 of having a specific problem dedicated to
floating point, but it seems exercises expecting floating point answers
will also inevitably have to touch on equality)
|
…946) This reverts commit 7eb0dc9. In #880 we discussed that tracks may need to use a tolerance in their floating point comparisons. In light of this, asking students to round the answer seems strangely arbitrary and theoretically doesn't prevent the need for having a tolerance. Despite this, I do not currently have an example where lacking a tolerance would have a false negative or false positive if a floating point literal of two decimal places is compared to a value that was rounded to two decimal places. So, then, the primary motivation is to avoid adding requirements whose reasons are unclear. Thus, remove the sentence completely. Tracks should add it if it is relevant for their track. Closes #945 by mutual exclusion. The tracks that currently implement the exercise, and whether their equality tests have tolerances: Please excuse me if I miscategorised your track because of my unfamiliarity with your language (and then correct me). Exactly equal: * https://github.com/exercism/csharp/blob/master/exercises/space-age/SpaceAgeTest.cs * https://github.com/exercism/cfml/blob/master/exercises/space-age/SpaceAgeTest.cfc * https://github.com/exercism/ecmascript/blob/master/exercises/space-age/space-age.spec.js * https://github.com/exercism/fsharp/blob/master/exercises/space-age/SpaceAgeTest.fs * https://github.com/exercism/javascript/blob/master/exercises/space-age/space-age.spec.js * https://github.com/exercism/kotlin/blob/master/exercises/space-age/src/test/kotlin/SpaceAgeTest.kt * https://github.com/exercism/lua/blob/master/exercises/space-age/space-age_spec.lua * https://github.com/exercism/perl5/blob/master/exercises/space-age/space.t * https://github.com/exercism/perl6/blob/master/exercises/space-age/space-age.t * https://github.com/exercism/python/blob/master/exercises/space-age/space_age_test.py * https://github.com/exercism/r/blob/master/exercises/space-age/test_space-age.R * https://github.com/exercism/scala/blob/master/exercises/space-age/src/test/scala/SpaceAgeTest.scala * https://github.com/exercism/swift/blob/master/exercises/space-age/Tests/SpaceAgeTests/SpaceAgeTests.swift * https://github.com/exercism/typescript/blob/master/exercises/space-age/space-age.test.ts Fixed tolerance 0.5 in either direction (so that the answer rounds to the desired value if rounding to closest integer) * https://github.com/exercism/elm/blob/master/exercises/space-age/tests/Tests.elm Fixed tolerance 0.01 in either direction * https://github.com/exercism/java/blob/master/exercises/space-age/src/test/java/SpaceAgeTest.java * https://github.com/exercism/objective-c/blob/master/exercises/space-age/SpaceAgeTest.m * https://github.com/exercism/php/blob/master/exercises/space-age/space-age_test.php * https://github.com/exercism/ruby/blob/master/exercises/space-age/space_age_test.rb * https://github.com/exercism/rust/blob/master/exercises/space-age/tests/space-age.rs Fixed tolerance 0.005 in either direction (so that the answer rounds to the desired value if rounding to two decimal places) * https://github.com/exercism/cpp/blob/master/exercises/space-age/space_age_test.cpp * https://github.com/exercism/clojure/blob/master/exercises/space-age/test/space_age_test.clj * https://github.com/exercism/common-lisp/blob/master/exercises/space-age/space-age-test.lisp * https://github.com/exercism/elixir/blob/master/exercises/space-age/space_age_test.exs * https://github.com/exercism/erlang/blob/master/exercises/space-age/test/space_age_tests.erl * https://github.com/exercism/haskell/blob/master/exercises/space-age/test/Tests.hs * https://github.com/exercism/lfe/blob/master/exercises/space-age/test/space-age-tests.lfe * https://github.com/exercism/ocaml/blob/master/exercises/space-age/test.ml * https://github.com/exercism/prolog/blob/master/exercises/space-age/space_age_tests.plt Variable tolerances (decided ahead-of-time): * https://github.com/exercism/c/blob/master/exercises/space-age/test/test_space_age.c
The expected age values are specified (in respective canonical-data.json) with 2-digit precision (e.g., 31.69), while the actual result is a float. Instead of forcing the solution to perform an arbitrary rounding, the test code verifies the result with certain precision (currently same 2-digit, for compatibility - can be eventually added to canonical-data.json itself). Aligned with the conclusion of the discussion in exercism/problem-specifications#880
* space-age: do not force rounding of solutions The expected age values are specified (in respective canonical-data.json) with 2-digit precision (e.g., 31.69), while the actual result is a float. Instead of forcing the solution to perform an arbitrary rounding, the test code verifies the result with certain precision (currently same 2-digit, for compatibility - can be eventually added to canonical-data.json itself). Aligned with the conclusion of the discussion in exercism/problem-specifications#880 * space-age: fix formatting
grains: Fix generator and regenerate tests
Inspired by exercism/kotlin#100.
Consistent with the rounding policy used by the canonical data.