exercism / go

Exercism exercises in Go.
https://exercism.org/tracks/go
MIT License
973 stars 649 forks source link

custom_set: add test case for unsorted subset #2652

Closed don-galak closed 1 year ago

don-galak commented 1 year ago

My approach for the Set type was to make it a string. So for the existing test cases to pass, all I had to do was:

type Set string

func New() Set {
    return "{}"
}

func (s Set) removeBraces() string {
    return s.String()[1 : len(s.String())-1]
}

func Subset(s1, s2 Set) bool {
    return strings.Contains(s2.String(), s1.removeBraces())
}

This obviously shouldn't be a correct solution, because if the given sub slice has the same elements, as the superset slice, but in an unsorted manner, then the result should be true. But my approach returns false.

github-actions[bot] commented 1 year ago

Hello. Thanks for opening a PR 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](https://forum.exercism.org/new-topic?title=custom_set:%20add%20test%20case%20for%20unsorted%20subset&body=My%20approach%20for%20the%20Set%20type%20was%20to%20make%20it%20a%20string.%20%20So%20for%20the%20existing%20test%20cases%20to%20pass,%20all%20I%20had%20to%20do%20was:%0D%0A%0D%0A%60%60%60%0D%0Atype%20Set%20string%0D%0A%0D%0Afunc%20New()%20Set%20%7B%0D%0A%09return%20%22%7B%7D%22%0D%0A%7D%0D%0A%0D%0Afunc%20(s%20Set)%20removeBraces()%20string%20%7B%0D%0A%09return%20s.String()%5B1%20:%20len(s.String())-1%5D%0D%0A%7D%0D%0A%0D%0Afunc%20Subset(s1,%20s2%20Set)%20bool%20%7B%0D%0A%09return%20strings.Contains(s2.String(),%20s1.removeBraces())%0D%0A%7D%0D%0A%60%60%60%0D%0A%0D%0AThis%20obviously%20shouldn't%20be%20a%20correct%20solution,%20because%20if%20the%20given%20sub%20slice%20has%20the%20same%20elements,%20as%20the%20superset%20slice,%20but%20in%20an%20unsorted%20manner,%20then%20the%20result%20should%20be%20true.%20But%20my%20approach%20returns%20false.&category=go) to copy this into a new topic there.


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