6 kyu
Temperature converter
504 of 1,004kusm
Loading description...
Functional Programming
Data Structures
Strings
Mathematics
Fundamentals
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
I've made a fork here that gets rid of rounding and tests for approximate equality.
Did this in python
Great simple challenge for people new to coding although the instruction could have been a little more clear on how to handle rounding. I discovered that I could simply cast my result to an integer at the end and get a correct answer (i.e. if my final number is 150.9, casting to an int would result in 150 which would be accepted) although the given instruction was simply to "round" to an integer, which in a mathematics sense typically implies that .5 and less (inclusive) rounds down where greater than 0.5 rounds up. I would recommend specifying to round down as it could give those who are new to coding a chance to learn that it is usual for numbers to be rounded down when they are cast to an int.
Overall this was a good kata. I did this kata in my own IDE in order to practice VIM and this was a good exercise for it.
Python:
The requirement "Round converted temp value to an integer(!)." is technically correct, but misleadingly fails to state that validation expects NO type casting to an int if the from and to scale are the same.
For example: temp = 80.48, from_scale = 'F', to_scale = 'F' -> It should work for random inputs too: 80 should equal 80.48
I would argue that this use of mixed-type returns is bad practise (i.e. always expect int, or always expect a 2-digit float), but at the very least this requirement could be detailed in the problem statement.
ideally there would be no rounding because why would there be? additionally, it doesn't specify tie breaker rule so you'll have python and js producing different results for 0.5
python new test framework + random tests are required. updated in this fork
.
Description should be language-agnostic
No random tests in Ruby
Nice Kata:)
Random tests sometimes has a result of
x.5
, which is suspectible to floating point errors depending on the exact way the conversion is calculated.Just an observation; for the Ruby version of this kata, please make the changes in the tests (and the code in general) to stick to Ruby's
snake_case
conventions.Very frustrating to find another Kata with non-descriptive error messages e.g. 1 failing with "Expected: 230, instead got: 63" Please list the inputs you are testing for so can actually deduce where the problem is. In this case, what was the input? What is the temp conversion?
Thanks
Resolved my submission (it was related to the Romer conversion) but this could still be a problem for others
You can always print arguments to the console to figure out what went wrong.
This comment has been hidden.
done
This comment has been hidden.
I posted a set of tests which I think would be useful and thorough. If you agree, please upvote my comment above, and hopefully the author will come round soon and implement them. ;)
nice set of tests. good idea to randomise the test cases also. upvoted. :)
done
Nice simple challenge, I think attempting to code these in way that could be used in multiple applications is what makes it challenging.
Ruby tests and submission evaluation should use 'convert_temp' rather than 'convertTemp'.
^ Someone please fix the submission evaluation tests. Can't submit Ruby solutions :(
You can still submit it, but you'll have to rename your function to get it to pass.
You say to round down to an integer. So shouldn't
-273.15
round down to274
, instead of the expected273
?I've figured it out, and I think you need to change your description. You clearly state that the temperature should be rounded down to an integer. This is very different to rounded. "Rounding down" means that if there's a decimal, the number will become smaller than the precise one. "Rounding up" means the number will become larger. "Rounding" (neither down nor up) means if the decimal is half or greater, it will become larger, otherwise it will become smaller.
Well, what i really want is to "cut off" the decimal part. I don't know how to word it, my language skills aren't good enough. If you have any idea how to put it in the description, I'll be happy to change it.
Well it seems from the tests that you're just rounding. So just say that. Say:
Round converted temp value to an integer(!)
(remove the "down"), and that should be fine.Done.
Ruby version submitted :)
The Ruby version is still running tests against the old casing (convertTemp instead of convert_temp). Just a head's up.
Ttue: regrettably I lack the power to edit it now; luckily you just need to adapt the function name to what you read in the test cases :)
No real issues, I just think it could use more test-cases
JS translation kumited.
may cause some issuses in case of float 2 integer .
Fixed. I hope it's not an issue anymore.
When working with linear conversions with fractional ratios, the results would be fractional numbers, though they could be pretty close to integers in some cases. See my solution for illustration of this problem. For a good kata, it would be nice to specify the expected behavior of the converter in this matter. I see three possible ways to deal with it:
A. Specify that the expected results are integers (nobody ever wishes to deal with fractional degrees in real life), and so the computed results must be rounded and returned as integers.
B. Specify that the expected results should be precide up to a certain number of decimal digits and expect the returned values to be floating point rounded to that number of decimal digits.
C. Specify that you expect the results as precise as possible, expect calculated values to be floating point, and compare them to the expected values with some expected inaccuracy, for example, you could create a special function for that and write tests like this:
Thanks! I chose the way A :)
Cool! :)
One little note: you say "temp is an integer", but in the examples there is:
convert_temp(373.15, "K", "N") # => 33
Ooops. Didn't notice that. I changed the description. Thank you again!
Very nice kata, thank you!
However, there're some issues that must be addressed.
First, please use
test.assert_equals()
instead oftest.expect()
. It provides information about what was the expected value and thus helps to locate and fix bugs. Please look here for details: http://www.codewars.com/docs/python-test-reference-1Changed.