Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

all-your-base exercise assigns negative numbers to unsigned data types. #175

Closed
Gamecock opened this issue Sep 20, 2017 · 1 comment
Closed

Comments

@Gamecock
Copy link
Contributor

All-your-base exercise has a couple of unit tests that assign negative numbers to uint data types.
example:

void test_first_base_is_negative(void)
{
   int8_t input[] = { 1 };
   int8_t expected[] = { 0 };
   test_rebase(-2, input, LENGTH(input), 10, expected, 0);
}

test_rebase is defined in the test case as:

void test_rebase(uint16_t input_base, int8_t input_digits[],
                 size_t input_length, uint16_t output_base,
                 int8_t expected_digits[], size_t expected_length)

We should either just delete those test cases or change the function prototype to allow negative bases.
I think deleting the test case is more C like, allowing negative numbers there seems like a Java thing.

One other test case was not implemented per the cannonical-data

    {
      "description": "negative digit",
      "property": "rebase",
      "input_base": 2,
      "input_digits": [1, -1, 1, 0, 1, 0],
      "output_base": 10,
      "expected": null
    },```
The `C` track is implemented with a negative base instead of a negative.  I can fix that case, or just delete it and make the arrays uint8_t[] vs int8_t[].

Let me know how you want me to proceed.
@wolf99
Copy link
Contributor

wolf99 commented Sep 20, 2017

Looking at the example for this I can see that it's only the test helper test_rebase() that uses unsigned parameter types. The implementation itself uses signed types.

My thought would be to keep the implementation using signed types and just correct the test helper to signed types also. This has two benefits. Firstly it allows tests for negative numbers (even if the correct behaviour for negative numbers is to not do a rebase). Secondly, signed types are generally considered safer than unsigned types when checking parameters potentially provided by client code (eg the tests).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants