-
Notifications
You must be signed in to change notification settings - Fork 0
Refactored project structure #6
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
Changes from 3 commits
9ceaf58
29dbd35
59452bd
757d5ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package assert | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func Equals(t *testing.T, expected interface{}, actual interface{}) { | ||
if !reflect.DeepEqual(expected, actual) { | ||
t.Errorf("%+v is not equal to %+v", expected, actual) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package criteria | ||
|
||
// CollabStyle .. | ||
type CollabStyle int | ||
|
||
const ( | ||
Team CollabStyle = iota + 1 | ||
Pair | ||
Mob | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package filter | ||
|
||
import ( | ||
"github.com/clean-code-projects/co-coders-api/internal/criteria" | ||
"github.com/clean-code-projects/co-coders-api/internal/user" | ||
akessner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
|
||
// OnCollabStyle .. | ||
func OnCollabStyle(users []user.User, coStyle criteria.CollabStyle) (matchedUsers []user.User) { | ||
matchedUsers = []user.User{} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A note for later. If we use this style on all the match filters then we will end up looping through the entire user database multiple times. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also had a thought about this type of filter method. Because it's filtering out all the users that don't match with this specific criteria, if you were to use a chain of filters (in a functional way), the 'filtered out' users would not be present to be matched to other criterias. So, perhaps just returning the matching users might not be enough. Instead we might want to consider using a new data structure that contains the user and a list of matches that have occurred. The function would be less of a filter and more of a matcher. |
||
for _, aUser := range users { | ||
if aUser.HasCollabStyle(coStyle) { | ||
matchedUsers = append(matchedUsers, aUser) | ||
} | ||
} | ||
return matchedUsers | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package filter_test | ||
|
||
import ( | ||
"github.com/clean-code-projects/co-coders-api/internal/assert" | ||
"github.com/clean-code-projects/co-coders-api/internal/criteria" | ||
"github.com/clean-code-projects/co-coders-api/internal/filter" | ||
"github.com/clean-code-projects/co-coders-api/internal/user" | ||
|
||
"testing" | ||
) | ||
|
||
func TestFilterOnCoStyleReturnsEmpty(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We changed coStyle to colabStyle, but didn't update the test names. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I forgot to update them. I'll do that. |
||
style := criteria.Team | ||
actual := filter.OnCollabStyle([]user.User{}, style) | ||
assert.Equals(t, []user.User{}, actual) | ||
} | ||
|
||
func TestFilterOnCoStyleReturnsNoMatch(t *testing.T) { | ||
aUser := user.New([]criteria.CollabStyle{criteria.Team}) | ||
users := []user.User{aUser} | ||
style := criteria.Mob | ||
actual := filter.OnCollabStyle(users, style) | ||
assert.Equals(t, []user.User{}, actual) | ||
} | ||
|
||
func TestFilterOnCoStyleReturnsAMatch(t *testing.T) { | ||
aUser := user.New([]criteria.CollabStyle{criteria.Team}) | ||
users := []user.User{aUser} | ||
style := criteria.Team | ||
actual := filter.OnCollabStyle(users, style) | ||
assert.Equals(t, []user.User{aUser}, actual) | ||
} | ||
|
||
func TestFilterOnCoStyleSubsetReturnsAMatch(t *testing.T) { | ||
aUser := user.New([]criteria.CollabStyle{criteria.Team, criteria.Pair}) | ||
users := []user.User{aUser} | ||
criterion := criteria.Team | ||
actual := filter.OnCollabStyle(users, criterion) | ||
assert.Equals(t, []user.User{aUser}, actual) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package user | ||
|
||
import "github.com/clean-code-projects/co-coders-api/internal/criteria" | ||
|
||
// User .. | ||
type User struct { | ||
CollabStyles []criteria.CollabStyle | ||
} | ||
|
||
// HasCollabStyle .. | ||
func (u User) HasCollabStyle(collabStyle criteria.CollabStyle) bool { | ||
for _, style := range u.CollabStyles { | ||
if style == collabStyle { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
// New .. | ||
func New(collabStyles []criteria.CollabStyle) User { | ||
akessner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return User{CollabStyles: collabStyles} | ||
} |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is more out of annoyance. The linter in VScode keeps complaining when you don't put a comment. I don't know how to turn off the linter rule. I'm ok to delete them. I mostly use goland, so it's not much of an issue for me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There got to be a way. I would say it is ok to keep them in this PR,
and the next PR add
.vscode/settings.json
to turn it off and remove these comments.And in the travis turn on any linter check. I know that go compiler do some linting itself, but don't know about which linter the vscode extension based on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have looked, but wasn't able to find a way. I ended up just creating a snippet that added them automatically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these comments supposed to be doc generating comments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I see these are required. We should probably add godoc to the travis yaml.
https://golang.org/doc/effective_go.html#commentary
Since these comments are actually treated like code, they probably don't break the clean code "no comment" rules. And we should probably fill them in. Thoughts?
I'll raise this on the channel.