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

Add sublist exercise #224

Merged
merged 13 commits into from
Nov 9, 2017
Merged

Add sublist exercise #224

merged 13 commits into from
Nov 9, 2017

Conversation

0xbarrett
Copy link
Contributor

size_t listTwoLength)
{
return (listOneLength == listTwoLength
&& !memcmp(listOne, listTwo, listOneLength));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing null pointers to memcmp works to an extent, but it's undefined.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a more explicit check for null is in order then.

return EQUAL;
} else if (is_sublist(listOne, listTwo, listOneLength, listTwoLength)) {
return SUBLIST;
} else if (is_superlist(listOne, listTwo, listOneLength, listTwoLength)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is_superlist(One, Two, OneLength, TwoLength) = is_sublist(Two, One, TwoLength, OneLength)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, yes it does 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think keeping the helper is_superlist and just having it call is_sublist with reversed params is still clearer though. Thoughts?

SUPERLIST
};

int check_lists(int *listOne, int *listTwo, size_t listOneLength,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return value should be the enum type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

{
int listTwo[] = { 1, 2, 3 };

TEST_ASSERT_EQUAL(SUBLIST, check_lists(NULL, listTwo, 0, sizeof(listTwo)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing the length argument as the size in bytes is pretty weird, and I don't think we do it in other array exercises. The length argument should instead be the number of elements.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I initially had it passing the number of elements and then I somehow convinced myself that it was weird, so I changed it. But, now I agree that it was right the first time.

@arcuru
Copy link
Contributor

arcuru commented Oct 26, 2017

Also remember that this needs the TEST_IGNORE() things too. #179

#include <stdbool.h>
#include <string.h>

static bool is_equal(int *listOne, int *listTwo, size_t listOneLength,
Copy link
Contributor

@wolf99 wolf99 Oct 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parameter names should also be snake_case rather than camelCase. Applies to parameters of all functions as well as variable names (such as those in the test file). Basically snake_case everything, but upper-case SNAKE_CASE enum values and macros 🐍 > 🐫 😄

(list_one, list_two, list_one_element_count, list_two_element_count)) {
return EQUAL;
} else
if (is_sublist
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did indent put else and if on two lines?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it definitely did. But now it doesn't seem to want to do it anymore.

} comparison_result_t;

comparison_result_t check_lists(int *listOne, int *listTwo,
size_t listOneLength, size_t listTwoLength);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure these variable names are lower_snake_case

@ryanplusplus
Copy link
Member

I don't have a great suggestion for new names, but the current names of the arguments makes it difficult for me to tell which list is being checked against which. Is list 1 being checked against list 2 or vice-versa? It would be great if we could find names that make that clear without having to infer it from the tests.

@0xbarrett
Copy link
Contributor Author

base_list & list_to_compare?

@ryanplusplus
Copy link
Member

LGTM

config.json Outdated
"control_flow_if_statements",
"control_flow_loops"
],
"uuid": "928e9860-0df9-5180-8529-7024c991b3616adc21a"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this need an "unlocked_by" field?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, according to exercism/discussions#175, if it's core: true, then it needs unlocked_by: null. I guess my question now is if everyone thinks this should be a core exercise or if it should be unlocked by something else.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's go with non-core. They want to have very few core exercises (I think 6-8?) so better to not burn them without a good reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, palindrome-products seems like a reasonable exercise to unlock this one, in my opinion

Copy link
Contributor

@wolf99 wolf99 Nov 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, palindrome-products seems like the best choice to unlock this IMO

return false;
}

static bool is_superlist(int *list_to_compare, int *base_list,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this function really necessary? I assumed that the calls to this would be replaced by calls to is_sublist, not that this function would be implemented as is_sublist.

@arcuru
Copy link
Contributor

arcuru commented Nov 4, 2017

This looks fine to me except for setting it to a non-core exercise (I think that needs a change to the config.json)

@wolf99
Copy link
Contributor

wolf99 commented Nov 9, 2017

This PR is blocking #227 and #226, it would be great to get those closed 😃
@RealBarrettBrown are you OK to make the change to the config.json?

@0xbarrett
Copy link
Contributor Author

Oops... I made the change a few days ago but forgot to commit.

@wolf99 wolf99 merged commit 5b10af6 into exercism:master Nov 9, 2017
@0xbarrett 0xbarrett deleted the sublist branch November 9, 2017 17:20
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

Successfully merging this pull request may close these issues.

None yet

5 participants