Last active
December 21, 2015 13:39
-
-
Save kazuhito-m/6314474 to your computer and use it in GitHub Desktop.
試験管。
検証のため書き捨てたコードを集めたモノです。
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 characters
import static org.hamcrest.CoreMatchers.is; | |
import static org.hamcrest.CoreMatchers.not; | |
import static org.junit.Assert.assertThat; | |
import java.util.LinkedHashSet; | |
import java.util.Set; | |
import org.junit.Before; | |
import org.junit.Test; | |
/** | |
* 試験管コード(検証のため書き捨てたコードを集めたモノ)。 | |
* @author kazuhito_m | |
* @version $Id$ | |
*/ | |
public class TestTube { | |
@Test | |
public void タブ文字はtrimで除外される対象なのか() { | |
String src = "\t\tabc\t\t"; | |
String dst= src.trim(); | |
System.out.println("結果:'" + dst + "'だった。"); | |
assertThat(dst , is("abc")); | |
} | |
@Test | |
public void コレクションSetの挙動確認() { | |
Set<String> stringSet = new LinkedHashSet<String>(); | |
// 前から足す | |
stringSet.add("a"); | |
stringSet.add("b"); | |
stringSet.add("c"); | |
stringSet.add("d"); | |
int i = 0; | |
for (String v : stringSet) { | |
System.out.println(++i + ":" + v); | |
} | |
Set<String> stringSet2 = new LinkedHashSet<String>(stringSet); | |
assertThat(stringSet2 , is(stringSet)); | |
// 同じのを足した際に、後ろに行かないか | |
stringSet.add("d"); | |
stringSet.add("a"); | |
i = 0; | |
for (String v : stringSet) { | |
System.out.println(++i + ":" + v); | |
} | |
// 元からあるものをadd()しても、並び方は変わらない。 | |
assertThat(stringSet2 , is(stringSet)); | |
} | |
@Test | |
public void セットのaddメソッドの挙動() { | |
// arange | |
Set<String> set = new HashSet<String>(); | |
// act & assert | |
assertThat(set.add("First") , is(true)); | |
assertThat(set.add("First") , is(false)); | |
assertThat(set.add("Second") , is(true)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment