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

Fixed #37. #38

Merged
merged 1 commit into from
Jun 17, 2014
Merged

Fixed #37. #38

merged 1 commit into from
Jun 17, 2014

Conversation

ashfurrow
Copy link
Contributor

No description provided.

@ashfurrow
Copy link
Contributor Author

Yeah actually this doesn't make sense. Hold up, yo.

@ashfurrow
Copy link
Contributor Author

That's better.

CGFloat y = (self.contentSize.height / self.originalSize.height) * point.y;
return CGPointMake(round(x), round(y));
BOOL withinBounds = fabsf(self.originalSize.width) > 0 && fabsf(self.originalSize.height) > 0;
NSAssert(withinBounds, @"originalSize dimension is zero, will result in NaN in returned value.");
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am confused by the name of this variable: "withinBounds"? Is that more like "hasOriginalSize"?

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 that's better 👍

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, when contentSize is zero, you get zero. That's possible, right? and would be assertable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure thing.

@ashfurrow
Copy link
Contributor Author

Fixed those issues.

@dblock
Copy link
Collaborator

dblock commented Jun 17, 2014

This definitely needs tests! Since you cannot stub the assert I would extract the asserting code into a function that returns a BOOL and stub it away in a test.

@dblock
Copy link
Collaborator

dblock commented Jun 17, 2014

Also please update CHANGELOG.

@ashfurrow
Copy link
Contributor Author

Ah, would you believe that I did update it but I forgot to add it to the staged changes? >.<

@ashfurrow
Copy link
Contributor Author

I definitely agree that this should be tested, though I'm not sure that I like the idea of a checking method doing the assertion, instead. Hmm...

@@ -1,3 +1,7 @@
### Next

* [#37](https://github.com/neilang/NAMapKit/issues/37) - Fix `NAMapView` from returning `{NaN, NaN}`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Needs an - [@ashfurrow](...), see format below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@dblock
Copy link
Collaborator

dblock commented Jun 17, 2014

What do you think of this? Makes it testable without a weird interface.

- (BOOL)checkContentSize
{
  BOOL hasContentSize = self.hasContentSize;
  NSAssert(hasContentSize, @"originalSize dimension is zero, will result in NaN in returned value.");
  return hasContentSize;
}

- (BOOL)hasContentSize
{
  return fabsf(self.originalSize.width) > 0 && fabsf(self.originalSize.height) > 0;
}

BOOL hasContentSize = [self checkContentSize];
if (...) { 
}

@ashfurrow
Copy link
Contributor Author

I think we can write a test to expect the raised exception:

it(@"asserts on zoomRelativePoint: with a zero content size", ^{
    expect(^{[mapView zoomRelativePoint:CGPointZero];}).to.raise(@"NSInternalInconsistencyException");
});

@ashfurrow
Copy link
Contributor Author

What do you think?

@dblock
Copy link
Collaborator

dblock commented Jun 17, 2014

I think there're two expectations here to test: one that it raises, but the other that it returns the original point in that case.

@ashfurrow
Copy link
Contributor Author

That's a valid point – I just don't like the idea that a method that's checking for a condition and returns success/failure might throw. Seems ... unsavoury somehow. Let me think on this.

@orta
Copy link
Collaborator

orta commented Jun 17, 2014

raising an exception and returning the original point is a really weird pattern IMO. I think just raising the exception should be enough, it's to catch programmer errors.

@ashfurrow
Copy link
Contributor Author

So maybe get rid of the else clause altogether?

@dblock
Copy link
Collaborator

dblock commented Jun 17, 2014

I'm cool with what @orta thinks.

This discussion btw would make for a good blog post :)

@ashfurrow
Copy link
Contributor Author

👍

You don't have to tell me twice.

@ashfurrow
Copy link
Contributor Author

💚

@@ -1,3 +1,7 @@
### Next

* [#37](https://github.com/neilang/NAMapKit/issues/37) - Fix `NAMapView` from returning `{NaN, NaN}` - [@ashfurrow](http://github.com/ashfurrow).
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this say "Added assert inside NAMapView#zoomRelativePoint when returning {NaN, NaN}"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sounds good

dblock added a commit that referenced this pull request Jun 17, 2014
@dblock dblock merged commit 23a4807 into neilang:master Jun 17, 2014
@dblock
Copy link
Collaborator

dblock commented Jun 17, 2014

k, merged, thanks for your cooperation and patience with me and @orta, @ashfurrow

@ashfurrow
Copy link
Contributor Author

No problem! Does one of you own the pod on trunk? I'll write up a blog post tomorrow.

@dblock
Copy link
Collaborator

dblock commented Jun 17, 2014

I'll do a release at some point soon, for now just use :head.

@ashfurrow
Copy link
Contributor Author

:head actually just uses the latest podspec version, not the git repo's head. I'll point to a commit hash, instead.

@dblock
Copy link
Collaborator

dblock commented Jun 18, 2014

That's nuts.

@orta
Copy link
Collaborator

orta commented Jun 18, 2014

that sounds unintuitive, are you sure that's the behavior? It should do that without the :head

Though it looks like the guides' section on this is broken, sigh.

@ashfurrow
Copy link
Contributor Author

Hmmm. Now I'm confused. I thought that was the behaviour, based on this stack overflow question and problems I've had with the ReactiveCocoa podspec. Now I'm not so sure.

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