blob: 1216c83155dbb43616e31b4f5ac7f57db92fcaca [file] [log] [blame]
Brett Chabote4be04d2011-01-21 23:33:22 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Brett Chabotfa4f6672011-09-01 17:05:01 -070016package com.android.ota.tests;
17
18import com.android.tradefed.testtype.IRemoteTest;
Brett Chabote4be04d2011-01-21 23:33:22 -080019
Brett Chabot0eabebe2011-09-12 16:15:42 -070020import junit.framework.TestCase;
21
Brett Chabote4be04d2011-01-21 23:33:22 -080022import java.util.Collection;
23import java.util.Iterator;
24
Brett Chabote4be04d2011-01-21 23:33:22 -080025/**
26 * Unit tests for {@link OtaStabilityTest}
27 */
28public class OtaStabilityTestTest extends TestCase {
29
30 /**
31 * Test basic case {@link OtaStabilityTest#split()}, where iterations divide evenly into each
32 * shards.
33 */
34 public void testSplit_even() {
35 OtaStabilityTest test = new OtaStabilityTest();
36 test.setIterations(10);
37 test.setShards(5);
Brett Chabotccfda2e2011-02-09 14:39:59 -080038 Collection<IRemoteTest> shards = test.split();
Brett Chabote4be04d2011-01-21 23:33:22 -080039 assertEquals(5, shards.size());
Brett Chabotccfda2e2011-02-09 14:39:59 -080040 for (IRemoteTest shardTest : shards) {
Brett Chabote4be04d2011-01-21 23:33:22 -080041 OtaStabilityTest otaShard = (OtaStabilityTest)shardTest;
42 assertEquals(2, otaShard.getIterations());
43 }
44 }
45
46 /**
47 * Test {@link OtaStabilityTest#split()}, where there are more iterations than shards.
48 */
49 public void testSplit_shards() {
50 OtaStabilityTest test = new OtaStabilityTest();
51 test.setIterations(5);
52 test.setShards(10);
Brett Chabotccfda2e2011-02-09 14:39:59 -080053 Collection<IRemoteTest> shards = test.split();
Brett Chabote4be04d2011-01-21 23:33:22 -080054 assertEquals(5, shards.size());
Brett Chabotccfda2e2011-02-09 14:39:59 -080055 for (IRemoteTest shardTest : shards) {
Brett Chabote4be04d2011-01-21 23:33:22 -080056 OtaStabilityTest otaShard = (OtaStabilityTest)shardTest;
57 assertEquals(1, otaShard.getIterations());
58 }
59 }
60
61 /**
62 * Test {@link OtaStabilityTest#split()}, where iterations does not divide evenly
63 */
64 public void testSplit_remainder() {
65 OtaStabilityTest test = new OtaStabilityTest();
66 test.setIterations(10);
67 test.setShards(3);
Brett Chabotccfda2e2011-02-09 14:39:59 -080068 Collection<IRemoteTest> shards = test.split();
Brett Chabote4be04d2011-01-21 23:33:22 -080069 assertEquals(3, shards.size());
Brett Chabotccfda2e2011-02-09 14:39:59 -080070 Iterator<IRemoteTest> iterator = shards.iterator();
71 IRemoteTest first = iterator.next();
Brett Chabote4be04d2011-01-21 23:33:22 -080072 assertEquals(3, ((OtaStabilityTest)first).getIterations());
73
Brett Chabotccfda2e2011-02-09 14:39:59 -080074 IRemoteTest second = iterator.next();
Brett Chabote4be04d2011-01-21 23:33:22 -080075 assertEquals(3, ((OtaStabilityTest)second).getIterations());
76
Brett Chabotccfda2e2011-02-09 14:39:59 -080077 IRemoteTest three = iterator.next();
Brett Chabote4be04d2011-01-21 23:33:22 -080078 assertEquals(4, ((OtaStabilityTest)three).getIterations());
79 }
Brett Chabote4be04d2011-01-21 23:33:22 -080080}