Skip to content

add tests for Data Model coverage #218

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

Merged
merged 20 commits into from
Jun 25, 2019
Merged

Conversation

jaeopt
Copy link
Contributor

@jaeopt jaeopt commented Jun 4, 2019

No description provided.

@jaeopt jaeopt changed the title (WIP): add tests for Data Model coverage add tests for Data Model coverage Jun 5, 2019
@@ -81,10 +81,13 @@ enum AttributeValue: Codable, Equatable, CustomStringConvertible {
return
}

if let value = try? container.decode(Int64.self) {
// Int values are all filtered as Double, so this Int parsing is not needed here
Copy link
Contributor

Choose a reason for hiding this comment

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

remove the comments and commented out code.

@@ -95,9 +95,6 @@ extension Array where Element == ConditionHolder {
}

func evaluate(op: LogicalOp, project: ProjectProtocol?, attributes: OptimizelyAttributes?) throws -> Bool {
guard self.count > 0 else {
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This condition is covered by the caller, so the guard-else condition never happens

Copy link
Contributor

Choose a reason for hiding this comment

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

Since the statement below will cause the app to blow up and you can easily add a test case that would cover this for code coverage, I'm going to ask that you put it back in there. The reason being that if for any reason you called evaluate on a array with one element, it will throw an exception as it exists now.

@@ -97,7 +97,7 @@ extension UserAttribute {

// invalid match - parsed for forward compatibility only (but evaluation fails)
guard let matchFinal = matchSupported else {
throw OptimizelyError.userAttributeInvalidMatch(self.match ?? "empty")
throw OptimizelyError.userAttributeInvalidMatch(self.match!)
Copy link
Contributor

Choose a reason for hiding this comment

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

there is no guarantee that match is not nil. so either bind it or default it but not bang.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nil match case is filtered out by "matchSupported", so safe for bang to remove unused code.
Will refactor the code to make safety more clear.

override public var description: String {
return "[url] \(url) (" + (String(data: body, encoding: .utf8) ?? "UNKNOWN") + ")"
}

Copy link
Contributor

Choose a reason for hiding this comment

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

why did you move this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like redundant to "isEqual" above. WIl be removed.

@@ -0,0 +1,23 @@
/****************************************************************************
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this class here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Looks like an error introduced while merging. Will clean up xcode project.

@@ -95,9 +95,6 @@ extension Array where Element == ConditionHolder {
}

func evaluate(op: LogicalOp, project: ProjectProtocol?, attributes: OptimizelyAttributes?) throws -> Bool {
guard self.count > 0 else {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since the statement below will cause the app to blow up and you can easily add a test case that would cover this for code coverage, I'm going to ask that you put it back in there. The reason being that if for any reason you called evaluate on a array with one element, it will throw an exception as it exists now.

}
}

func testEvaluate_OperatorOnly() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Where is the error thrown here? This appears to now hit the self[1...] where it would throw an exception

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 guess you expect out-of-bound exception here. It does not happen since the array size is 1 here ( "and" is not filtered out yet).

Copy link
Contributor

@thomaszurkan-optimizely thomaszurkan-optimizely left a comment

Choose a reason for hiding this comment

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

LGTM

@thomaszurkan-optimizely thomaszurkan-optimizely merged commit d368e03 into master Jun 25, 2019
@thomaszurkan-optimizely thomaszurkan-optimizely deleted the jae/coverDataModel branch June 25, 2019 17:27
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.

3 participants