Skip to content

Worker Movement Testing

Alexander Johnson edited this page Aug 29, 2022 · 3 revisions

Overview

These JUnit test cases aim to check if the WorkerMovementTask passes the following functionality tests:

  1. shouldMoveOnStart: when the start method is called on the task, the entity should be moving towards the assigned target.
void shouldMoveOnStart() {
        Vector2 target = new Vector2(10f, 10f);
        WorkerMovementTask task = new WorkerMovementTask(target);
        Entity entity = new Entity().addComponent(new PhysicsComponent());
        PhysicsMovementComponent movementComponent = new PhysicsMovementComponent();
        entity.addComponent(movementComponent);
        entity.create();

        task.create(() -> entity);
        task.start();
        assertTrue(movementComponent.getMoving());
        assertEquals(target, movementComponent.getTarget());
        assertEquals(Task.Status.ACTIVE, task.getStatus());
    }
  1. shouldStopWhenClose: when the task is started and the position of the entity comes within stopping distance of the target (0.01f by default), then the entity should stop moving.
void shouldStopWhenClose() {
        WorkerMovementTask task = new WorkerMovementTask(new Vector2(10f, 10f));
        task.setStopDistance(1f); // Stopping distance for entity
        Entity entity = new Entity().addComponent(new PhysicsComponent());
        PhysicsMovementComponent movementComponent = new PhysicsMovementComponent();
        entity.addComponent(movementComponent);
        entity.setPosition(5f, 5f);
        entity.create();

        task.create(() -> entity);
        task.start();
        task.update();
        assertTrue(movementComponent.getMoving());
        assertEquals(Task.Status.ACTIVE, task.getStatus());

        entity.setPosition(10f, 9f);
        task.update();
        assertFalse(movementComponent.getMoving());
        assertEquals(Task.Status.FINISHED, task.getStatus());
    }
  1. shouldMoveToNewTarget: when the task is started and the entity is moving towards its first target then, if the target is changed before the entity stops, it should move towards and stop at the second target.
void shouldMoveToNewTarget() {
        Vector2 firstTarget = new Vector2(10f, 10f); // First entity target
        WorkerMovementTask task = new WorkerMovementTask(firstTarget);
        task.setStopDistance(1f); // Stopping distance for entity
        Entity entity = new Entity().addComponent(new PhysicsComponent());
        PhysicsMovementComponent movementComponent = new PhysicsMovementComponent();
        entity.addComponent(movementComponent);
        entity.setPosition(5f, 5f);
        entity.create();

        // Create WorkerMovementTask and assign entity
        task.create(() -> entity);
        task.start();
        task.update();
        assertTrue(movementComponent.getMoving());
        assertEquals(Task.Status.ACTIVE, task.getStatus());

        // Change target of entity
        Vector2 secondTarget = new Vector2(-10f, -10f);
        task.setTarget(secondTarget);

        // Move entity next to first target; should still be moving
        entity.setPosition(10f, 9f);
        task.update();
        assertTrue(movementComponent.getMoving());
        assertEquals(Task.Status.ACTIVE, task.getStatus());

        // Move entity next to second target; should stop moving
        entity.setPosition(-10f, -9f);
        task.update();
        assertFalse(movementComponent.getMoving());
        assertEquals(Task.Status.FINISHED, task.getStatus());
    }

Table of Contents

Home

Game

Game Home

Design Influences

Gameplay Features

Style

Story

Friendly Units
Map
City
Buildings
Unit Selections

Spell

Game User Testing: Theme of Unit Selection & Spell System

UI User Testing

Tutorial

Resource Stats Display

Loading Screen Bar

Health Bars
In Game menu
  • Feature
  • User Testing:In Game Menu

Landscape Tile Design

Landscape Tile Design Feedback

Weather Design

Weather Design Feedback

Camera Movement

Enemy design

Enemy Units

Enemy AI

How Animation Works

Map Flooding

Game Engine

Getting Started

Entities and Components

Service Locator

Loading Resources

Logging

Unit Testing

Debug Terminal

Input Handling

UI

Animations

Audio

AI

Physics

Game Screens and Areas

Terrain

Concurrency & Threading

Settings

Troubleshooting

MacOS Setup Guide

Clone this wiki locally