|
| 1 | +/* |
| 2 | + * Catroid: An on-device visual programming system for Android devices |
| 3 | + * Copyright (C) 2010-2022 The Catrobat Team |
| 4 | + * (<http://developer.catrobat.org/credits>) |
| 5 | + * |
| 6 | + * This program is free software: you can redistribute it and/or modify |
| 7 | + * it under the terms of the GNU Affero General Public License as |
| 8 | + * published by the Free Software Foundation, either version 3 of the |
| 9 | + * License, or (at your option) any later version. |
| 10 | + * |
| 11 | + * An additional term exception under section 7 of the GNU Affero |
| 12 | + * General Public License, version 3, is available at |
| 13 | + * http://developer.catrobat.org/license_additional_term |
| 14 | + * |
| 15 | + * This program is distributed in the hope that it will be useful, |
| 16 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | + * GNU Affero General Public License for more details. |
| 19 | + * |
| 20 | + * You should have received a copy of the GNU Affero General Public License |
| 21 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 22 | + */ |
| 23 | +package org.catrobat.catroid.test.content.actions |
| 24 | + |
| 25 | +import junit.framework.Assert |
| 26 | +import org.catrobat.catroid.common.BrickValues |
| 27 | +import org.catrobat.catroid.common.ScreenValues |
| 28 | +import org.catrobat.catroid.content.ActionFactory |
| 29 | +import org.catrobat.catroid.content.Sprite |
| 30 | +import org.catrobat.catroid.content.actions.GoToRandomPositionAction |
| 31 | +import org.junit.Before |
| 32 | +import org.junit.Rule |
| 33 | +import org.junit.Test |
| 34 | +import org.junit.rules.ExpectedException |
| 35 | +import org.junit.runner.RunWith |
| 36 | +import org.junit.runners.JUnit4 |
| 37 | + |
| 38 | +@RunWith(JUnit4::class) |
| 39 | +class GoToRandomPositionActionTest { |
| 40 | + @JvmField |
| 41 | + @Rule |
| 42 | + val exception: ExpectedException = ExpectedException.none() |
| 43 | + |
| 44 | + private var sprite: Sprite? = null |
| 45 | + private var dummySprite: Sprite? = null |
| 46 | + private var action: GoToRandomPositionAction? = null |
| 47 | + |
| 48 | + @Before |
| 49 | + @Throws(Exception::class) |
| 50 | + fun setUp() { |
| 51 | + sprite = Sprite("testSprite") |
| 52 | + dummySprite = Sprite("dummySprite") |
| 53 | + ScreenValues.setToDefaultScreenSize() |
| 54 | + action = sprite!!.actionFactory.createGoToAction( |
| 55 | + sprite, dummySprite, BrickValues.GO_TO_RANDOM_POSITION |
| 56 | + ) as GoToRandomPositionAction |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + fun testGoToOtherSpriteAction() { |
| 61 | + sprite!!.look.xInUserInterfaceDimensionUnit = 0f |
| 62 | + sprite!!.look.yInUserInterfaceDimensionUnit = 0f |
| 63 | + |
| 64 | + Assert.assertEquals(0f, sprite!!.look.xInUserInterfaceDimensionUnit) |
| 65 | + Assert.assertEquals(0f, sprite!!.look.yInUserInterfaceDimensionUnit) |
| 66 | + |
| 67 | + action!!.act(1f) |
| 68 | + |
| 69 | + Assert.assertEquals(action!!.randomXPosition, sprite!!.look.xInUserInterfaceDimensionUnit) |
| 70 | + Assert.assertEquals(action!!.randomYPosition, sprite!!.look.yInUserInterfaceDimensionUnit) |
| 71 | + } |
| 72 | + |
| 73 | + @Test |
| 74 | + fun testNullActor() { |
| 75 | + val factory = ActionFactory() |
| 76 | + val action = factory.createGoToAction(null, dummySprite, BrickValues.GO_TO_RANDOM_POSITION) |
| 77 | + exception.expect(NullPointerException::class.java) |
| 78 | + action.act(1.0f) |
| 79 | + } |
| 80 | +} |
0 commit comments