[1091] | 1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany |
---|
| 2 | // |
---|
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
---|
| 4 | // you may not use this file except in compliance with the License. |
---|
| 5 | // You may obtain a copy of the License at |
---|
| 6 | // |
---|
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
---|
| 8 | // |
---|
| 9 | // Unless required by applicable law or agreed to in writing, software |
---|
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
---|
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
| 12 | // See the License for the specific language governing permissions and |
---|
| 13 | // limitations under the License. |
---|
| 14 | |
---|
| 15 | package de.ugoe.cs.autoquest.ui; |
---|
| 16 | |
---|
| 17 | import static org.junit.Assert.*; |
---|
| 18 | import static org.mockito.Mockito.mock; |
---|
| 19 | |
---|
| 20 | import java.util.Collection; |
---|
| 21 | import java.util.LinkedList; |
---|
| 22 | import java.util.List; |
---|
| 23 | import java.util.logging.Level; |
---|
| 24 | |
---|
| 25 | import org.junit.Before; |
---|
| 26 | import org.junit.Test; |
---|
| 27 | |
---|
| 28 | import de.ugoe.cs.autoquest.commands.sequences.CMDsplitSequences; |
---|
| 29 | import de.ugoe.cs.autoquest.eventcore.Event; |
---|
| 30 | import de.ugoe.cs.autoquest.eventcore.IEventType; |
---|
| 31 | import de.ugoe.cs.autoquest.test.CommandRunner; |
---|
| 32 | import de.ugoe.cs.util.console.GlobalDataContainer; |
---|
| 33 | import de.ugoe.cs.util.console.TextConsole; |
---|
| 34 | |
---|
| 35 | /** |
---|
| 36 | * |
---|
| 37 | * @author Patrick Harms |
---|
| 38 | */ |
---|
| 39 | public class CMDsplitSequencesTest { |
---|
| 40 | |
---|
| 41 | /** |
---|
| 42 | * |
---|
| 43 | */ |
---|
| 44 | @Before |
---|
| 45 | public void setUp() { |
---|
| 46 | new TextConsole(Level.FINEST); |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | /** |
---|
| 50 | * |
---|
| 51 | */ |
---|
| 52 | @SuppressWarnings("unchecked") |
---|
| 53 | @Test |
---|
| 54 | public void test() { |
---|
| 55 | String sequencesName = "sequences"; |
---|
| 56 | IEventType type = mock(IEventType.class); |
---|
| 57 | |
---|
| 58 | Collection<List<Event>> sequences = new LinkedList<List<Event>>(); |
---|
| 59 | |
---|
| 60 | for (int i = 0; i < 5; i++) { |
---|
| 61 | List<Event> sequence = new LinkedList<Event>(); |
---|
| 62 | |
---|
| 63 | for (int j = 0; j < 10; j++) { |
---|
| 64 | Event event = new Event(type); |
---|
[1096] | 65 | |
---|
| 66 | if (j < 3) { |
---|
| 67 | event.setTimestamp(((i + 1) * 50) + j); |
---|
| 68 | } |
---|
| 69 | else if (j < 7) { |
---|
| 70 | event.setTimestamp(((i + 1) * 50) + j + 15); |
---|
| 71 | } |
---|
| 72 | else { |
---|
| 73 | event.setTimestamp(((i + 1) * 50) + j + 30); |
---|
| 74 | } |
---|
| 75 | |
---|
[1091] | 76 | sequence.add(event); |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | sequences.add(sequence); |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | GlobalDataContainer.getInstance().addData(sequencesName, sequences); |
---|
| 83 | CommandRunner.runCommand(CMDsplitSequences.class, "5", sequencesName); |
---|
| 84 | |
---|
| 85 | Object result = GlobalDataContainer.getInstance().getData(sequencesName); |
---|
| 86 | |
---|
| 87 | assertNotNull(result); |
---|
| 88 | assertTrue(result instanceof Collection<?>); |
---|
| 89 | |
---|
| 90 | sequences = (Collection<List<Event>>) result; |
---|
| 91 | |
---|
[1096] | 92 | assertEquals(15, sequences.size()); |
---|
[1091] | 93 | |
---|
| 94 | for (List<Event> sequence : sequences) { |
---|
| 95 | assertNotNull(sequence); |
---|
[1096] | 96 | assertTrue((sequence.size() == 3) || (sequence.size() == 4)); |
---|
[1091] | 97 | } |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | } |
---|