Created
November 19, 2012 18:23
-
-
Save aeg/4112500 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
// Case #1 | |
// リスト内の要素の重複を排除したリストを作る | |
def list = ['a', 'b', 'c', 'b', 'c'] | |
assert list.unique() == ['a', 'b', 'c'] | |
// 少し関連して注意すべき点。 | |
// PowerAssertの結果について、少し注意すべき。 | |
// 下記のアサートを実行すると、 | |
// assert list.unique() == ['a'] | |
// | |
// 下記のような結果が得られる。 | |
// assert list.unique() == ['a'] | |
// | | | | |
// | | false | |
// | [a, b, c] | |
// [a, b, c] | |
// | |
// 最初のリストは['a', 'b', 'c', 'b', 'c'] であるべきなのに、 | |
// PowerAssertの結果としては、unique() が実行された結果になっている。 | |
// これは複雑なオブジェクトの場合、最新の値しか保持をしていないので、 | |
// 変更前が表示できないという理由からこのような状況になっている。 | |
// 単純な変数に変更を与えるようなテストの場合には変更前も正しく表示される。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment