#My C++ Triangle thing is fully functioning, but doesn't work on Exercism.
18 messages · Page 1 of 1 (latest)
Take a look at the tests. This is the first one:
TEST_CASE("isosceles_triangles_have_last_two_sides_equal")
{
REQUIRE(triangle::flavor::isosceles == triangle::kind(3, 4, 4));
}
It calls the function triangle::kind with three arguments, and expects a result that is equal to triangle::flavor::isosceles
Reading the tests is important, they specify all the technical details.
Whenever C++ programmers think of a type with a few distinct values (and they can even name those values) they think of an enum or even better: enum class. You have to define that type in the .h file.
like Siebenschlaefer said, the tests are telling you the return type it expects
REQUIRE(triangle::flavor::equilateral == triangle::kind(2, 2, 2)); means that kind(2, 2, 2) needs to return an enumerator of class flavor of value equilateral
for the tests, the left side is the expected value
so in your h file, you need to add a declaration to the triangle namespace for that enum type, and then use that enum type in your definition of kind
no, not at all
here's the concept page that covers enums https://exercism.org/tracks/cpp/concepts/enums
if you haven't done that associated learning exercise yet, that should point you in the right direction
that should give you what you need for Triangle yes
namespaces are a way to organize and contain the functions and types and constants you use, you use them specifically because you don't want those things to be global
For namespaces there's also a concept: https://exercism.org/tracks/cpp/concepts/namespaces
Multiple issue:
kindreturns anint. Thisintcannot be compared (without casts) with an anenum class.- The function in the
.hfile returnsflavor. This `flavor is a type, not a value. You have to return one of the three values. - The
.cppfile also defineskind. You can only have one definition for a function (the so-called ODR rule) - The function in the
.cppfile assigns something toflavor. Butflavoris a type, not a variable.
This error without error message often happens when a solution throws an exception where the tests do not expect one.
There's a semicolon missing after the throw statement.
Take a look at the test "very_small_triangles_are_legal". It calls triangle::kind(0.4, 0.6, 0.3).
But since the parameters in your solution have the type int these arguments all get converted to 0, and then the function throws an exception where none is expected.
And one last thing that I noticed: You might want to double-check the type of the exception that the tests expect.