Skip to content

Commit

Permalink
fetch main (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
miniJmo authored Nov 12, 2024
1 parent 77f4f97 commit 920e4f5
Show file tree
Hide file tree
Showing 176 changed files with 5,906 additions and 3,510 deletions.
37 changes: 18 additions & 19 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ dotnet_diagnostic.IDE0005.severity = error
file_header_template = unset

# this. and Me. preferences
dotnet_style_qualification_for_event = false:silent
dotnet_style_qualification_for_field = false:silent
dotnet_style_qualification_for_method = false:silent
dotnet_style_qualification_for_property = false:silent
dotnet_style_qualification_for_event = false:warning
dotnet_style_qualification_for_field = false:warning
dotnet_style_qualification_for_method = false:warning
dotnet_style_qualification_for_property = false:warning

# Language keywords vs BCL types preferences
dotnet_style_predefined_type_for_locals_parameters_members = true:silent
dotnet_style_predefined_type_for_member_access = true:silent
dotnet_style_predefined_type_for_locals_parameters_members = true:warning
dotnet_style_predefined_type_for_member_access = true:warning

# Parentheses preferences
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent
Expand All @@ -46,7 +46,7 @@ dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent

# Modifier preferences
dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent
dotnet_style_require_accessibility_modifiers = for_non_interface_members:warning

# Expression-level preferences
dotnet_style_coalesce_expression = true:suggestion
Expand Down Expand Up @@ -77,19 +77,19 @@ dotnet_remove_unnecessary_suppression_exclusions = none
#### C# Coding Conventions ####

# var preferences
csharp_style_var_elsewhere = false:silent
csharp_style_var_for_built_in_types = false:silent
csharp_style_var_when_type_is_apparent = false:silent
csharp_style_var_elsewhere = true:warning
csharp_style_var_for_built_in_types = true:warning
csharp_style_var_when_type_is_apparent = true:warning

# Expression-bodied members
csharp_style_expression_bodied_accessors = true:silent
csharp_style_expression_bodied_constructors = false:silent
csharp_style_expression_bodied_indexers = true:silent
csharp_style_expression_bodied_accessors = true:warning
csharp_style_expression_bodied_constructors = false:warning
csharp_style_expression_bodied_indexers = true:warning
csharp_style_expression_bodied_lambdas = true:suggestion
csharp_style_expression_bodied_local_functions = false:silent
csharp_style_expression_bodied_methods = false:silent
csharp_style_expression_bodied_operators = false:silent
csharp_style_expression_bodied_properties = true:silent
csharp_style_expression_bodied_local_functions = false:warning
csharp_style_expression_bodied_methods = false:warning
csharp_style_expression_bodied_operators = false:warning
csharp_style_expression_bodied_properties = true:warning

# Pattern matching preferences
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
Expand All @@ -106,7 +106,7 @@ csharp_prefer_static_local_function = true:warning
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:silent

# Code-block preferences
csharp_prefer_braces = true:silent
csharp_prefer_braces = true:warning
csharp_prefer_simple_using_statement = true:suggestion

# Expression-level preferences
Expand Down Expand Up @@ -359,4 +359,3 @@ dotnet_naming_style.s_camelcase.required_prefix = s_
dotnet_naming_style.s_camelcase.required_suffix =
dotnet_naming_style.s_camelcase.word_separator =
dotnet_naming_style.s_camelcase.capitalization = camel_case

76 changes: 22 additions & 54 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,7 @@ on:

### Refer to https://game.ci/docs/github/getting-started
jobs:
checklicense:
name: Check for UNITY_LICENSE in GitHub Secrets
runs-on: ubuntu-latest
outputs:
is_unity_license_set: ${{ steps.checklicense_job.outputs.is_unity_license_set }}
steps:
- name: Check whether unity activation requests should be done
id: checklicense_job
env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
run: |
echo "Skip activation job: ${{ env.UNITY_LICENSE != '' }}"
export is_unity_license_set="${{ env.UNITY_LICENSE != '' }}"
echo "is_unity_license_set=$is_unity_license_set" >> $GITHUB_OUTPUT
activation:
needs: checklicense
if: needs.checklicense.outputs.is_unity_license_set == 'false'
name: Request manual activation file 🔑
runs-on: ubuntu-latest
steps:
# Request manual activation file
- name: Request manual activation file
id: getManualLicenseFile
uses: game-ci/unity-request-activation-file@v2
# Upload artifact (Unity_v20XX.X.XXXX.alf)
- name: Expose as artifact
uses: actions/upload-artifact@v3
with:
name: ${{ steps.getManualLicenseFile.outputs.filePath }}
path: ${{ steps.getManualLicenseFile.outputs.filePath }}

test:
needs: checklicense
if: needs.checklicense.outputs.is_unity_license_set == 'true'
permissions:
checks: write
name: Run all tests ✨
Expand Down Expand Up @@ -105,23 +69,27 @@ jobs:
with:
name: Build-${{ matrix.targetPlatform }}
path: build


format:
name: Check formatting

lint:
name: Lint
runs-on: ubuntu-latest
container: unityci/editor:ubuntu-2022.3.51f1-linux-il2cpp-3.1.0
steps:
- uses: actions/checkout@v3
with:
lfs: true
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Format CustomScriptsAssembly.csproj
run: dotnet format CustomScriptsAssembly.csproj --verify-no-changes --verbosity diagnostic
- name: Format PlayModeTests.csproj
run: dotnet format PlayModeTests.csproj --verify-no-changes --verbosity diagnostic
- name: Format EditTests.csproj
run: dotnet format EditTests.csproj --verify-no-changes --verbosity diagnostic

- uses: actions/checkout@v1
- name: Generate Solution
env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
UNITY_SERIAL: ${{ secrets.UNITY_SERIAL }}
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
run: |
unity-editor -nographics -logFile /dev/stdout -quit -username "$UNITY_EMAIL" -password "$UNITY_PASSWORD" -serial "$UNITY_SERIAL"
unity-editor -nographics -logFile /dev/stdout -customBuildName LinuxProjectFileBuild -projectPath . -executeMethod Packages.Rider.Editor.RiderScriptEditor.SyncSolution -quit
- name: Print the files in the folder
run: ls
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Format
run: dotnet format MAEPS.sln --exclude "Assets/RosMessages/" --exclude "Assets/YamlDotNet/" --verify-no-changes
108 changes: 68 additions & 40 deletions Assets/EditTests/CoverageCalculatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,46 @@
// Original repository: https://github.com/MalteZA/MAES

using System.Collections.Generic;

using Maes.Map;
using Maes.Map.MapGen;
using Maes.Statistics;

using NUnit.Framework;

using UnityEngine;

using Random = System.Random;

namespace EditTests {
public class CoverageCalculatorTest {
namespace EditTests
{
public class CoverageCalculatorTest
{

private CoverageCalculator<ExplorationCell> _coverageCalculator;
private SimulationMap<Tile> _collisionMap;
private SimulationMap<ExplorationCell> _explorationMap;
private const int RandomSeed = 123;
private const int Width=50, Height=50;
private const int Width = 50, Height = 50;

[SetUp]
public void InitializeCalculatorAndMaps() {
public void InitializeCalculatorAndMaps()
{
_collisionMap = GenerateCollisionMap();
_explorationMap = _collisionMap.FMap(tile => new ExplorationCell(!Tile.IsWall(tile.Type)));
_coverageCalculator = new CoverageCalculator<ExplorationCell>(_explorationMap, _collisionMap);
}

// Generates a collision map where only the edge tiles are solid
private static SimulationMap<Tile> GenerateCollisionMap() {
SimulationMapTile<Tile>[,] tiles = new SimulationMapTile<Tile>[Width, Height];
private static SimulationMap<Tile> GenerateCollisionMap()
{
var tiles = new SimulationMapTile<Tile>[Width, Height];
Tile.Rand = new Random(RandomSeed);
var wall = Tile.GetRandomWall();
for (int x = 0; x < Width; x++) {
for (int y = 0; y < Height; y++) {
for (var x = 0; x < Width; x++)
{
for (var y = 0; y < Height; y++)
{
var tile = IsGeneratedTileSolid(new Vector2Int(x, y)) ? wall : new Tile(TileType.Room);
tiles[x, y] = new SimulationMapTile<Tile>(() => tile);
}
Expand All @@ -59,50 +69,56 @@ private static SimulationMap<Tile> GenerateCollisionMap() {
}

// All edges are solid. All other tiles are non-solid
private static bool IsGeneratedTileSolid(Vector2Int tileCoordinate) {
private static bool IsGeneratedTileSolid(Vector2Int tileCoordinate)
{
return (tileCoordinate.x == 0 ||
tileCoordinate.y == 0 ||
tileCoordinate.x == Width - 1 ||
tileCoordinate.x == Width - 1 ||
tileCoordinate.y == Height - 1);
}

[Test]
public void RobotOnTopOfTileCoverageTest() {
public void RobotOnTopOfTileCoverageTest()
{
// The test robot is positioned in the middle of the coarse tile at coordinates (20, 20)
// (Equivalent to the slam tile at (40, 40)
var robotWorldPos = new Vector2(20.25f, 20.25f);
var ((_, cell1), (_, cell2)) = _explorationMap.GetMiniTilesByCoarseTileCoordinate(robotWorldPos);

// Assert that none of cells are covered in advance
Assert.IsFalse(cell1.IsCovered);
Assert.IsFalse(cell2.IsCovered);

// Register coverage for the testing robot
_coverageCalculator.UpdateRobotCoverage(robotWorldPos, 1, (_, _, _, _) => {
_coverageCalculator.UpdateRobotCoverage(robotWorldPos, 1, (_, _, _, _) =>
{
});

// Assert that the status of the tiles has now changed
Assert.IsTrue(cell1.IsCovered);
Assert.IsTrue(cell2.IsCovered);
}


[Test]
[TestCase(20.00f, 20.00f)]
[TestCase(20.5f, 20.5f)]
[TestCase(20.25f, 20.25f)]
[TestCase(20.75f, 20.75f)]
[TestCase(20.49f, 20.49f)]
[TestCase(20.99f, 20.99f)]
public void AdjacentTilesAreCoveredTest(float robotX, float robotY) {
public void AdjacentTilesAreCoveredTest(float robotX, float robotY)
{
// The test robot is positioned in the middle of the coarse tile at coordinates (20, 20)
// (Equivalent to the slam tile at (40, 40)
var robotWorldPos = new Vector2(robotX, robotY);

// Find all cells that are immediate neighbours of tile currently occupied by the robot
var cells = new List<ExplorationCell>();
for (int x = -1; x < 1; x++) {
for (int y = -1; y < 1; y++) {
for (var x = -1; x < 1; x++)
{
for (var y = -1; y < 1; y++)
{
var xOffset = x * 0.5f;
var yOffset = y * 0.5f;
var ((_, cell1), (__, cell2)) = _explorationMap
Expand All @@ -111,59 +127,72 @@ public void AdjacentTilesAreCoveredTest(float robotX, float robotY) {
cells.Add(cell2);
}
}

// Assert that none of cells are covered in advance
foreach (var cell in cells)
foreach (var cell in cells)
{
Assert.IsFalse(cell.IsCovered);

}

// Register coverage for the testing robot
_coverageCalculator.UpdateRobotCoverage(robotWorldPos, 1, (_, _, _, _) => {
_coverageCalculator.UpdateRobotCoverage(robotWorldPos, 1, (_, _, _, _) =>
{
});

// Assert that the status of the tiles has now changed
foreach (var cell in cells)
foreach (var cell in cells)
{
Assert.IsTrue(cell.IsCovered);
}
}


[Test]
public void CoverageTimeUpdateTest() {
public void CoverageTimeUpdateTest()
{
// The test robot is positioned in the middle of the coarse tile at coordinates (20, 20)
// (Equivalent to the slam tile at (40, 40)
var robotWorldPos = new Vector2(20.25f, 20.25f);
var ((_, cell1), (_, cell2)) = _explorationMap.GetMiniTilesByCoarseTileCoordinate(robotWorldPos);

const int coverageTick = 123456;
// Register coverage for the testing robot
_coverageCalculator.UpdateRobotCoverage(robotWorldPos, coverageTick, (_, _, _, _) => {
_coverageCalculator.UpdateRobotCoverage(robotWorldPos, coverageTick, (_, _, _, _) =>
{
});

// Assert the the coverage time is updated
Assert.AreEqual(cell1.LastCoverageTimeInTicks, coverageTick);
Assert.AreEqual(cell2.LastCoverageTimeInTicks, coverageTick);

// Cover again at one tick later
_coverageCalculator.UpdateRobotCoverage(robotWorldPos, coverageTick + 1, (_, _, _, _) => {
_coverageCalculator.UpdateRobotCoverage(robotWorldPos, coverageTick + 1, (_, _, _, _) =>
{
});
Assert.AreEqual(cell1.LastCoverageTimeInTicks, coverageTick + 1);
Assert.AreEqual(cell2.LastCoverageTimeInTicks, coverageTick + 1);
}

[Test]
public void TilesAreMarkedCoverableCorrectly() {
public void TilesAreMarkedCoverableCorrectly()
{
// Copy the existing exploration map and to get a new map where all CanBeCovered flags are true
var freshExplorationMap = _explorationMap.FMap((cell) => new ExplorationCell(cell.IsExplorable));
for (int x = 0; x < Width; x++) {
for (int y = 0; y < Height; y++) {
for (var x = 0; x < Width; x++)
{
for (var y = 0; y < Height; y++)
{
Assert.IsTrue(freshExplorationMap.GetTileByLocalCoordinate(x, y).IsTrueForAll(cell => cell.CanBeCovered));
}
}

new CoverageCalculator<ExplorationCell>(freshExplorationMap, _collisionMap);
// Pass the new exploration map to the coverage calculator which should cause the solid tiles to be
// marked as non-coverable
for (int x = 0; x < Width; x++) {
for (int y = 0; y < Height; y++) {
for (var x = 0; x < Width; x++)
{
for (var y = 0; y < Height; y++)
{
// We now expect the tiles have a 'CanBeCovered' status that is opposite to the solid status of tile
// (ie. solid tiles cannot be covered and non-solid ones can be covered)
var isSolid = IsGeneratedTileSolid(new Vector2Int(x, y));
Expand All @@ -173,5 +202,4 @@ public void TilesAreMarkedCoverableCorrectly() {
}
}
}
}

}
Loading

0 comments on commit 920e4f5

Please sign in to comment.