Elevate your data management. Join a lively chat to learn how streaming data can improve real-time decision-making, and how to reduce costs.
Platform Engineering: Enhance the developer experience, establish secure environments, automate self-service tools, and streamline workflows
Software Developer at Atech
Sao Paulo, BR
Joined Jun 2008
Stats
| Reputation: | 21 |
| Pageviews: | 60.6K |
| Articles: | 1 |
| Comments: | 8 |
Comments
Sep 03, 2013 · Mr B Loid
Here is my Ruby solution: http://rafaelnaufal.com/blog/2013/09/03/k-palindromes-puzzle/
Jul 21, 2013 · Eric Senunas
v=[1,5,6,7,9,10];sum = v.reduce(:+);count=0;index = (0...v.size).detect { |i| count += v[i]; count * 2 == sum};index == nil ? nil : index + 1Result: index = 4Jun 20, 2013 · Tony Thomas
In Ruby:
Dec 02, 2009 · Geertjan Wielenga
Dec 02, 2009 · Tad Anderson
Feb 10, 2009 · Mr B Loid
@MarkThornton
"You supposed to throw an exception instead of using an assert. However this doesn't change the problem with respect to testing --- you have to provide a valid value."
What if the unnecessary values for testing would be substituted by "NullObjects"?
Then, the code would look like this:
testSecureHouse() {
Door door = new Door();
Window window = new Window();
House house = new House(door, window,
HouseTest.createRoofForTest(), HouseTest.createKitchenForTest(),
HouseTest.createLivingRoomForTest(),
HouseTest.createBedRoomForTest());
house.secure();
assertTrue(door.isLocked());
assertTrue(window.isClosed());
}
If Roof, Kitchen, LivingRoom and BedRoom were interfaces, the null objects can have the same contract (implementing the same interface). The null objects can have only one instance because there is no need to have a lot of instances of the same NullObject. Of course they don't need to be hard-coded, they can be configured and created with Test Data Builders. Each of the collaborators instantiate Null Objects that it depends.
Feb 10, 2009 · Mr B Loid
Sometimes ago I blogged about ways of indicating the absence of an object:
http://rnaufal.livejournal.com/10017.html
One interesting comment I received about using Assert to validate input:
"There's a document in the JDK docs titled Programming With Assertions that says:
Do not use assertions for argument checking in public methods"
Feb 10, 2009 · Mr B Loid
Sometimes ago I blogged about ways of indicating the absence of an object:
http://rnaufal.livejournal.com/10017.html
One interesting comment I received about using Assert to validate input:
"There's a document in the JDK docs titled Programming With Assertions that says:
Do not use assertions for argument checking in public methods"