OLD | NEW |
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 List<int, ZeroingAllocationPolicy> list(4); | 58 List<int, ZeroingAllocationPolicy> list(4); |
59 list.Add(1); | 59 list.Add(1); |
60 list.Add(2); | 60 list.Add(2); |
61 list.Add(3); | 61 list.Add(3); |
62 list.Add(4); | 62 list.Add(4); |
63 | 63 |
64 // Add an existing element, the backing store should have to grow. | 64 // Add an existing element, the backing store should have to grow. |
65 list.Add(list[0]); | 65 list.Add(list[0]); |
66 CHECK_EQ(1, list[4]); | 66 CHECK_EQ(1, list[4]); |
67 } | 67 } |
| 68 |
| 69 // Test that we can add all elements from a list to another list. |
| 70 TEST(ListAddAll) { |
| 71 List<int, ZeroingAllocationPolicy> list(4); |
| 72 list.Add(0); |
| 73 list.Add(1); |
| 74 list.Add(2); |
| 75 |
| 76 CHECK_EQ(3, list.length()); |
| 77 for (int i = 0; i < 3; i++) { |
| 78 CHECK_EQ(i, list[i]); |
| 79 } |
| 80 |
| 81 List<int, ZeroingAllocationPolicy> other_list(4); |
| 82 |
| 83 // Add no elements to list since other_list is empty. |
| 84 list.AddAll(other_list); |
| 85 CHECK_EQ(3, list.length()); |
| 86 for (int i = 0; i < 3; i++) { |
| 87 CHECK_EQ(i, list[i]); |
| 88 } |
| 89 |
| 90 // Add three elements to other_list. |
| 91 other_list.Add(0); |
| 92 other_list.Add(1); |
| 93 other_list.Add(2); |
| 94 |
| 95 // Copy the three elements from other_list to list. |
| 96 list.AddAll(other_list); |
| 97 CHECK_EQ(6, list.length()); |
| 98 for (int i = 0; i < 6; i++) { |
| 99 CHECK_EQ(i % 3, list[i]); |
| 100 } |
| 101 } |
OLD | NEW |