forked from sbastn/com.happyprog.pairhero
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sebastian Hermida
committed
Apr 21, 2011
1 parent
3fec5be
commit 3915ae6
Showing
2 changed files
with
63 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
test/com/happyprog/pairhero/views/TimeFormatLearningTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.happyprog.pairhero.views; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import org.junit.Test; | ||
|
||
public class TimeFormatLearningTest { | ||
@Test | ||
public void oneSecond() throws Exception { | ||
assertEquals("00:01", format(1)); | ||
} | ||
|
||
@Test | ||
public void twentySeconds() throws Exception { | ||
assertEquals("00:20", format(20)); | ||
} | ||
|
||
@Test | ||
public void oneMinute() throws Exception { | ||
assertEquals("01:00", format(60)); | ||
} | ||
|
||
@Test | ||
public void oneMinuteAndThirtySeconds() throws Exception { | ||
assertEquals("01:30", format(90)); | ||
} | ||
|
||
@Test | ||
public void twentyFiveMinutes() throws Exception { | ||
assertEquals("25:00", format(1500)); | ||
} | ||
|
||
@Test | ||
public void twentyFourMinutesAndFiftyNineSeconds() throws Exception { | ||
assertEquals("24:59", format(1499)); | ||
} | ||
|
||
private String format(int time) { | ||
int minutes = time / 60; | ||
int seconds = time % 60; | ||
|
||
return String.format("%s:%s", fill(minutes), fill(seconds)); | ||
} | ||
|
||
private Object fill(int seconds) { | ||
if (seconds < 10) { | ||
return String.format("0%d", seconds); | ||
} | ||
return String.format("%d", seconds); | ||
} | ||
} |