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
// Case #1 | |
// リストの要素をランダムに並び替える | |
def list1 = ['a', 'b', 'c', 'd'] | |
def list2 = [] | |
while(list1.size() > 0) { | |
index = new Random().nextInt(list1.size()) | |
list2.add(list1[index]) | |
list1.remove(index) | |
} |
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
// Case #1 | |
// 指定した条件を満たす要素を削除したリストを作成する | |
def list1 = [1, 3, 7, 10, 13] | |
assert list1.findAll{!(it < 10)} == [10, 13] | |
// Case #2 | |
// 指定した条件を満たす要素をリストから削除する |
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
// Case #1 | |
// リストの要素を条件で抽出する。 | |
def list1 = ['a', 'b', 'c', 'd'] | |
assert list1.grep{ it > 'b' } == ['c', 'd'] | |
// Case #2 | |
// リストの要素をリストの条件で抽出する。 |
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 org.junit.Test | |
import org.junit.experimental.runners.Enclosed | |
import org.junit.runner.RunWith; | |
import spock.lang.Specification | |
@RunWith(Enclosed.class) | |
class SpockJUnitMixTest { | |
static class Spockテストグループ1 extends Specification{ | |
def "Spockテスト1-1"() { | |
when: |
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
// Case #1 | |
// 数値の2進数、8進数、16進数、n進数表現(n進数以外はリテラル) | |
// 2進数(00001111) | |
assert 0b00001111 == 15 | |
// 8進数(0100) | |
assert 0100 == 64 | |
// 16進数(ff) |
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
// Case #1 | |
// 数値の2進数、8進数、16進数、n進数表現 | |
// 2進数(00001111) | |
assert 0b00001111 == 15 | |
// 8進数(0100) | |
assert 0100 == 64 | |
// 16進数(ff) |
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
// Case #1 | |
// 自然対数を計算する | |
assert Math.log(72) ==4.276666119016055 | |
assert Math.log(Math.E) == 1 | |
// Case #2 | |
// 10を底とした対数を計算する |
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
// Case #1 | |
// リストの任意の要素をインデックス指定で削除する | |
def list1 = ['a', 'b', 'c', 'd'] | |
list1.remove(2) | |
assert list1 == ['a', 'b', 'd'] | |
// Case #2 |
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
// Case #1 | |
// リストのリストをフラットなリストにする | |
assert ['a', ['b', 'c',['d', 'e']]].flatten() == ['a', 'b', 'c', 'd', 'e'] | |
// Case #2 | |
// リスト展開演算子を用いて、リストを展開する | |
assert ['a', 'b', *['c', 'd']] == ['a', 'b', 'c', 'd'] |
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
// Case #1 | |
// リストの集合演算的な和をとる | |
def list1 = ['a' ,'b', 'c'] | |
def list2 = ['b', 'c', 'd', 'e'] | |
assert (list1 + list2).unique() == ['a', 'b', 'c', 'd', 'e'] | |
// Case #2 | |
// リストの集合演算的な積をとる(リストの共通部分をとる) |