-
-
Save liquiddandruff/ca4eb98fdd063b6c250b to your computer and use it in GitHub Desktop.
Revisions
-
huljas revised this gist
Aug 3, 2011 . 1 changed file with 7 additions and 20 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,47 +1,34 @@ import org.junit.Test; import java.util.Date; import static org.junit.Assert.assertEquals; public class StringFormatTest { @Test public void basicInteger() { assertEquals("123456", String.format("%d", 123456)); } @Test public void leftPaddingIntegerWithZeroes() { assertEquals("007", String.format("%03d", 7)); } @Test public void integerWithLeadingSpace() { assertEquals(" 11", String.format("% 4d", 11)); } @Test public void floatWithTwoDecimals() { assertEquals("1123.35", String.format("%.2f", 1123.345566)); } @Test public void time() { assertEquals("09:26:42", String.format("%tT", 1312180002230L)); } @Test public void date() { assertEquals("2011-08-01", String.format("%tF", new Date(1312180002230L))); } @Test public void dateAndTime() { assertEquals("09:26:42.231 2011.08.01", String.format("%1$tH:%1$tM:%1$tS.%1$tL %1$tY.%1$tm.%1$td", 1312180002231L)); } } -
huljas revised this gist
Aug 3, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -41,7 +41,7 @@ public void date() { @Test public void dateAndTime() { assertEquals("09:26:42.231 2011.08.01", String.format("%1$tH:%1$tM:%1$tS.%1$tL %1$tY.%1$tm.%1$td", 1312180002231L)); } } -
huljas revised this gist
Aug 3, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ import static org.junit.Assert.assertEquals; /** * @author huljas */ public class StringFormatTest { -
huljas created this gist
Aug 3, 2011 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ import org.junit.Test; import java.util.Date; import static org.junit.Assert.assertEquals; /** * @author exthulja */ public class StringFormatTest { @Test public void basicInteger() { assertEquals("123456", String.format("%d", 123456)); } @Test public void leftPaddingIntegerWithZeroes() { assertEquals("007", String.format("%03d", 7)); } @Test public void integerWithLeadingSpace() { assertEquals(" 11", String.format("% 4d", 11)); } @Test public void floatWithTwoDecimals() { assertEquals("1123.35", String.format("%.2f", 1123.345566)); } @Test public void time() { assertEquals("09:26:42", String.format("%tT", 1312180002230L)); } @Test public void date() { assertEquals("2011-08-01", String.format("%tF", new Date(1312180002230L))); } @Test public void dateAndTime() { assertEquals("09:26:42 2011.08.01", String.format("%1$tH:%1$tM:%1$tS %1$tY.%1$tm.%1$td", 1312180002230L)); } }