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

<Description> : Adding random for CGFloat and tests for the same. #262

Merged
merged 1 commit into from
Oct 27, 2016
Merged

<Description> : Adding random for CGFloat and tests for the same. #262

merged 1 commit into from
Oct 27, 2016

Conversation

Khalian
Copy link
Collaborator

@Khalian Khalian commented Oct 20, 2016

: feature/test

@EZSwiftExtensionsBot
Copy link

EZSwiftExtensionsBot commented Oct 20, 2016

2 Messages
📖 Executed 104 tests, with 0 failures (0 unexpected) in 1.478 (1.709) seconds
📖 Executed 100 tests, with 0 failures (0 unexpected) in 1.104 (1.329) seconds

Generated by 🚫 danger

@codecov-io
Copy link

codecov-io commented Oct 20, 2016

Current coverage is 52.56% (diff: 100%)

Merging #262 into master will increase coverage by 22.06%

@@             master       #262   diff @@
==========================================
  Files            45         67    +22   
  Lines          2010       2966   +956   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits            613       1559   +946   
- Misses         1397       1407    +10   
  Partials          0          0          

Powered by Codecov. Last update b602e50...17bcca3

@Khalian
Copy link
Collaborator Author

Khalian commented Oct 20, 2016

I added the change.

I have no idea why NSURL tests are failing. Perhaps create an issue to look into it?

@lfarah
Copy link
Collaborator

lfarah commented Oct 25, 2016

@Khalian I think we need a better name for random(). I wouldn't know that it could only be from 0 to 1 since floats can go bigger than just 1.

@lfarah
Copy link
Collaborator

lfarah commented Oct 25, 2016

@piv199 what do you think?

@lfarah
Copy link
Collaborator

lfarah commented Oct 25, 2016

@vsouza says that a good name would be randomFraction()



/// EZSE: Returns a random floating point number between 0.0 and 1.0, inclusive.
public static func random() -> CGFloat {
Copy link
Collaborator

Choose a reason for hiding this comment

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

@lfarah suggests better name

As for me, I would stick with random because it's the default behavior.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We should not change working experience for already presented function unless it was wrong. Image thousand of people will get an update and crashes in their programs due to this change.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@piv199 What if we deprecate this one and create a new? We already did this on some other methods:

    /// EZSE: Checks if array contains at least 1 instance of the given object type
    @available(*, deprecated: 1.8, renamed: "containsType(of:)")
    public func containsInstanceOf<T>(_ element: T) -> Bool {
        return containsType(of: element)
    }

    /// EZSE: Gets the object at the specified index, if it exists.
    @available(*, deprecated: 1.8, renamed: "get(at:)")
    public func get(_ index: Int) -> Element? {
        return get(at: index)
    }

    /// EZSE: Checks if all elements in the array are true of false
    @available(*, deprecated: 1.8, renamed: "testAll(is:)")
    public func testIfAllIs(_ condition: Bool) -> Bool {
        return testAll(is: condition)
    }

@Khalian
Copy link
Collaborator Author

Khalian commented Oct 25, 2016

Well I wanted to model the random around this : https://docs.oracle.com/javase/7/docs/api/java/lang/Math.html#random()

But i dont mind changing it to randomFraction(). Once we reach consensus on the name I will make the change.

}

/// EZSE: Returns a random floating point number in the range min...max, inclusive.
public static func random(range: ClosedRange<CGFloat>) -> CGFloat {
Copy link
Collaborator

Choose a reason for hiding this comment

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

random(in range:ClosedRange)
random(in range:Range)

what do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmmm I think these functions are good but random by itself is still useful.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@lfarah yes of course, I just point to

CGFloat.random(in: 300..<600.34) instead of CGFloat.random(range: 300..<600.34)

And possibly add range if it not works, can't test. 300..<600.34 will work?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So we have a consensus on this ? randomFraction with in: instead of range: ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

The matter is that what range will random() generate values, if high random, then dots precision is small.

Copy link
Collaborator

Choose a reason for hiding this comment

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

What actually the case for random to use. Where?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok I can drop the random with range then.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@Khalian I'm still sure it would be great to have such extension, let it be 👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok so what do you want me to do at this point?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@Khalian Personally I, nothing :)

@Khalian
Copy link
Collaborator Author

Khalian commented Oct 26, 2016

Closing this pull request as reviewers unable to reach a consensus.

@Khalian Khalian closed this Oct 26, 2016
@lfarah
Copy link
Collaborator

lfarah commented Oct 26, 2016

@Khalian wanna open an issue and we can discuss and vote?

@piv199 piv199 reopened this Oct 26, 2016
}

/// EZSE: Returns a random floating point number in the range min...max, inclusive.
public static func random(range: ClosedRange<CGFloat>) -> CGFloat {
Copy link
Collaborator

Choose a reason for hiding this comment

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

random(in range: ClosedRange<CGFloat>)

}

func testRandomWithinRange() {
let range = CGFloat(0.0)...CGFloat(10.0)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please, test also CGFloat(0.0)..<CGFloat(10.0)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done. In is a keyword so used within.

@piv199 piv199 merged commit 6889c1c into Esqarrouth:master Oct 27, 2016
@piv199
Copy link
Collaborator

piv199 commented Oct 27, 2016

@Khalian Thanks very much for your patience and contributing 👍

@lfarah
Copy link
Collaborator

lfarah commented Oct 27, 2016

Yes @Khalian, you're awesome! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants