Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 51 lines (43 sloc) 1.467 kb
793d3881 » Jon-Paul Lussier
2011-03-15 First commit, 32 completed koans
1 require File.expand_path(File.dirname(__FILE__) + '/edgecase')
2
3 class AboutArrayAssignment < EdgeCase::Koan
4 def test_non_parallel_assignment
5 names = ["John", "Smith"]
6 assert_equal ["John", "Smith"], names
7 end
8
9 def test_parallel_assignments
10 first_name, last_name = ["John", "Smith"]
11 assert_equal "John", first_name
12 assert_equal "Smith", last_name
13 end
14
15 def test_parallel_assignments_with_extra_values
16 first_name, last_name = ["John", "Smith", "III"]
17 assert_equal "John", first_name
18 assert_equal "Smith", last_name
19 end
20
21 def test_parallel_assignments_with_splat_operator
22 first_name, *last_name = ["John", "Smith", "III"]
23 assert_equal "John", first_name
24 assert_equal ["Smith", "III"], last_name
25 end
26
27 def test_parallel_assignments_with_too_few_variables
28 first_name, last_name = ["Cher"]
29 assert_equal "Cher", first_name
30 assert_equal nil, last_name
31 end
32
33 def test_parallel_assignments_with_subarrays
34 first_name, last_name = [["Willie", "Rae"], "Johnson"]
35 assert_equal ["Willie", "Rae"], first_name
36 assert_equal "Johnson", last_name
37 end
38
39 def test_parallel_assignment_with_one_variable
40 first_name, = ["John", "Smith"]
41 assert_equal "John", first_name
42 end
43
44 def test_swapping_with_parallel_assignment
45 first_name = "Roy"
46 last_name = "Rob"
47 first_name, last_name = last_name, first_name
48 assert_equal "Rob", first_name
49 assert_equal "Roy", last_name
50 end
51 end
Something went wrong with that request. Please try again.