exercism / c

Exercism exercises in C.
https://exercism.org/tracks/c
MIT License
298 stars 182 forks source link

Darts - is there an inconsistency between the tests and the overview page description? #839

Closed armhzjz closed 1 year ago

armhzjz commented 1 year ago

According to the overview page of the Darts problem, the radius of the concentric circles are defined as:

The outer circle has a radius of 10 units (this is equivalent to the total radius for the entire target), the middle circle a radius of 5 units, and the inner circle a radius of 1. Of course, they are all centered at the same point (that is, the circles are concentric defined by the coordinates (0, 0).

However, the test "test_just_outside_the_middle_circle" is defined as:

{
   coordinate_t landing_position = { -3.6F, -3.6F };
   uint8_t expected = 1;
   uint8_t actual = score(landing_position);
   TEST_ASSERT_EQUAL_UINT8(expected, actual);
}

This is confusing because, (also according to the overview page of the Darts problem) the expected number of points for positions under the radius of 5.0 (i.e. middle circle) should be 5 (not 1). This causes the tests to failed (or pushes the user to implement something that passes the test - ignoring the specification of the problem).

I see more discrepancies between some other tests and the specification of the problem. Am I missing something? I see the overview page was recently updated (Dec. 2022). Were the tests not updated as well?

github-actions[bot] commented 1 year ago

Hello. Thanks for opening an issue on Exercism. We are currently in a phase of our journey where we have paused community contributions to allow us to take a breather and redesign our community model. You can learn more in this blog post. As such, all issues and PRs in this repository are being automatically closed.

That doesn't mean we're not interested in your ideas, or that if you're stuck on something we don't want to help. The best place to discuss things is with our community on the Exercism Community Forum. You can use this link%20the%20expected%20number%20of%20points%20for%20positions%20under%20the%20radius%20of%205.0%20(i.e.%20middle%20circle)%20should%20be%205%20(not%201).%20This%20causes%20the%20tests%20to%20failed%20(or%20pushes%20the%20user%20to%20implement%20something%20that%20passes%20the%20test%20-%20ignoring%20the%20specification%20of%20the%20problem).%0D%0A%0D%0AI%20see%20more%20discrepancies%20between%20some%20other%20tests%20and%20the%20specification%20of%20the%20problem.%0D%0AAm%20I%20missing%20something?%0D%0AI%20see%20the%20overview%20page%20was%20recently%20updated%20(Dec.%202022).%20Were%20the%20tests%20not%20updated%20as%20well?&category=c) to copy this into a new topic there.


Note: If this issue has been pre-approved, please link back to this issue on the forum thread and a maintainer or staff member will reopen it.

armhzjz commented 1 year ago

The very first test is inconsistent with the second test. The first test is defined as:

static void test_missed_target(void)
{
   coordinate_t landing_position = { -9.0F, 9.0F };
   uint8_t expected = 0;
   uint8_t actual = score(landing_position);
   TEST_ASSERT_EQUAL_UINT8(expected, actual);
}

while the second test is defined as:

Some basic Git commands are:

static void test_on_the_outer_circle(void)
{
      // delete this line to run test
   coordinate_t landing_position = { 0.0F, 10.0F };
   uint8_t expected = 1;
   uint8_t actual = score(landing_position);
   TEST_ASSERT_EQUAL_UINT8(expected, actual);
}

Shouldn't the expected values be 1 and 1 respectively?

ryanplusplus commented 1 year ago

According to the overview page of the Darts problem, the radius of the concentric circles are defined as:

The outer circle has a radius of 10 units (this is equivalent to the total radius for the entire target), the middle circle a radius of 5 units, and the inner circle a radius of 1. Of course, they are all centered at the same point (that is, the circles are concentric defined by the coordinates (0, 0).

However, the test "test_just_outside_the_middle_circle" is defined as:

{
   coordinate_t landing_position = { -3.6F, -3.6F };
   uint8_t expected = 1;
   uint8_t actual = score(landing_position);
   TEST_ASSERT_EQUAL_UINT8(expected, actual);
}

This is confusing because, (also according to the overview page of the Darts problem) the expected number of points for positions under the radius of 5.0 (i.e. middle circle) should be 5 (not 1). This causes the tests to failed (or pushes the user to implement something that passes the test - ignoring the specification of the problem).

The distance from origin to { -3.6F, -3.6F } is ~5.09 so this is outside of the middle circle and inside of the outer circle. This is consistent with the description in the overview:

If the dart lands in the outer circle of the target, player earns 1 point. If the dart lands in the middle circle of the target, player earns 5 points.

Since the distance from origin is greater than 5, it earns only 1 point.

I see more discrepancies between some other tests and the specification of the problem. Am I missing something? I see the overview page was recently updated (Dec. 2022). Were the tests not updated as well?

The problem specifications and implementations are machine-generated and not always updated in lockstep, but the changes are usually just additions, removals, or tweaks of tests, not wholesale re-definitions of the problem.

ryanplusplus commented 1 year ago

The very first test is inconsistent with the second test. The first test is defined as:

static void test_missed_target(void)
{
   coordinate_t landing_position = { -9.0F, 9.0F };
   uint8_t expected = 0;
   uint8_t actual = score(landing_position);
   TEST_ASSERT_EQUAL_UINT8(expected, actual);
}

while the second test is defined as:

Some basic Git commands are:

static void test_on_the_outer_circle(void)
{
      // delete this line to run test
   coordinate_t landing_position = { 0.0F, 10.0F };
   uint8_t expected = 1;
   uint8_t actual = score(landing_position);
   TEST_ASSERT_EQUAL_UINT8(expected, actual);
}

Shouldn't the expected values be 1 and 1 respectively?

For the first test, the distance from origin is ~12.73 and this is greater than 10 so 0 points are earned. I suspect that you are not correctly calculating the distance from origin. Check out the Wikipedia article on Euclidean distance.

armhzjz commented 1 year ago

So, what I missed, is that the function should then calculate the hypotenuse based on the Cartesian coordinates?

armhzjz commented 1 year ago

For the first test, the distance from origin is ~12.73 and this is greater than 10 so 0 points are earned. I suspect that you are not correctly calculating the distance from origin. Check out the Wikipedia article on Euclidean distance.

Right. Thank you very much again.