Skip to content

Commit

Permalink
Run pre-commit / dotnet-format once to reformat everything
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeage committed Jun 27, 2024
1 parent 2a25ded commit 88f74be
Show file tree
Hide file tree
Showing 350 changed files with 75,942 additions and 67,311 deletions.
1 change: 0 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -483,4 +483,3 @@ jobs:
target_commitish: ${{ needs.configuration.outputs.currentrelease }}
tag_name: ${{ needs.configuration.outputs.version }}
files: releases/*

67 changes: 36 additions & 31 deletions Assets/Editor/tests/model/controller/TouchPadLocationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,44 @@
using NUnit.Framework;
using UnityEngine;

namespace com.google.apps.peltzer.client.model.controller {
namespace com.google.apps.peltzer.client.model.controller
{

[TestFixture]
// Tests for TouchpadLocation.
public class TouchpadLocationTest {
[Test]
public void TestBasicQuadrants() {
NUnit.Framework.Assert.IsTrue(
TouchpadLocation.RIGHT.Equals(TouchpadLocationHelper.GetTouchpadLocation(new Vector2(.5f, 0))));
NUnit.Framework.Assert.IsTrue(
TouchpadLocation.TOP.Equals(TouchpadLocationHelper.GetTouchpadLocation(new Vector2(0, .5f))));
NUnit.Framework.Assert.IsTrue(
TouchpadLocation.LEFT.Equals(TouchpadLocationHelper.GetTouchpadLocation(new Vector2(-.5f, 0))));
NUnit.Framework.Assert.IsTrue(
TouchpadLocation.BOTTOM.Equals(TouchpadLocationHelper.GetTouchpadLocation(new Vector2(0, -.5f))));
}
[TestFixture]
// Tests for TouchpadLocation.
public class TouchpadLocationTest
{
[Test]
public void TestBasicQuadrants()
{
NUnit.Framework.Assert.IsTrue(
TouchpadLocation.RIGHT.Equals(TouchpadLocationHelper.GetTouchpadLocation(new Vector2(.5f, 0))));
NUnit.Framework.Assert.IsTrue(
TouchpadLocation.TOP.Equals(TouchpadLocationHelper.GetTouchpadLocation(new Vector2(0, .5f))));
NUnit.Framework.Assert.IsTrue(
TouchpadLocation.LEFT.Equals(TouchpadLocationHelper.GetTouchpadLocation(new Vector2(-.5f, 0))));
NUnit.Framework.Assert.IsTrue(
TouchpadLocation.BOTTOM.Equals(TouchpadLocationHelper.GetTouchpadLocation(new Vector2(0, -.5f))));
}

[Test]
public void TestCenter() {
NUnit.Framework.Assert.IsTrue(
TouchpadLocation.CENTER.Equals(TouchpadLocationHelper.GetTouchpadLocation(new Vector2(0, 0))));
}
[Test]
public void TestCenter()
{
NUnit.Framework.Assert.IsTrue(
TouchpadLocation.CENTER.Equals(TouchpadLocationHelper.GetTouchpadLocation(new Vector2(0, 0))));
}

[Test]
public void TestXYCombinations() {
NUnit.Framework.Assert.IsTrue(
TouchpadLocation.TOP.Equals(TouchpadLocationHelper.GetTouchpadLocation(new Vector2(.1f, .5f))));
NUnit.Framework.Assert.IsTrue(
TouchpadLocation.BOTTOM.Equals(TouchpadLocationHelper.GetTouchpadLocation(new Vector2(.1f, -.5f))));
NUnit.Framework.Assert.IsTrue(
TouchpadLocation.BOTTOM.Equals(TouchpadLocationHelper.GetTouchpadLocation(new Vector2(-.1f, -.5f))));
NUnit.Framework.Assert.IsTrue(
TouchpadLocation.LEFT.Equals(TouchpadLocationHelper.GetTouchpadLocation(new Vector2(-.5f, 0))));
[Test]
public void TestXYCombinations()
{
NUnit.Framework.Assert.IsTrue(
TouchpadLocation.TOP.Equals(TouchpadLocationHelper.GetTouchpadLocation(new Vector2(.1f, .5f))));
NUnit.Framework.Assert.IsTrue(
TouchpadLocation.BOTTOM.Equals(TouchpadLocationHelper.GetTouchpadLocation(new Vector2(.1f, -.5f))));
NUnit.Framework.Assert.IsTrue(
TouchpadLocation.BOTTOM.Equals(TouchpadLocationHelper.GetTouchpadLocation(new Vector2(-.1f, -.5f))));
NUnit.Framework.Assert.IsTrue(
TouchpadLocation.LEFT.Equals(TouchpadLocationHelper.GetTouchpadLocation(new Vector2(-.5f, 0))));
}
}
}
}
295 changes: 151 additions & 144 deletions Assets/Editor/tests/model/core/CommandTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,149 +18,156 @@
using NUnit.Framework;
using UnityEngine;

namespace com.google.apps.peltzer.client.model.core {

[TestFixture]
// Tests for Command and implementations.
public class CommandTest {

[Test]
public void TestCompositeMove() {
int meshOne = 1;
int meshTwo = 2;

Model model = new Model(new Bounds(Vector3.zero, Vector3.one * 10));

// Add two meshes.
model.ApplyCommand(new AddMeshCommand(Primitives.AxisAlignedBox(
meshOne, Vector3.zero, Vector3.one, /* materialId */ 3)));
model.ApplyCommand(new AddMeshCommand(Primitives.AxisAlignedBox(
meshTwo, Vector3.one, Vector3.one, /* materialId */ 4)));

// Check the meshes are where we think they are.
NUnit.Framework.Assert.Less(
Vector3.Distance(model.GetMesh(meshOne).offset,
new Vector3(0, 0, 0)), 0.001f);
NUnit.Framework.Assert.Less(
Vector3.Distance(model.GetMesh(meshTwo).offset,
new Vector3(1, 1, 1)), 0.001f);

// Make and apply a CompositeCommand that moves both of them.
MoveMeshCommand move1 = new MoveMeshCommand(
meshOne, new Vector3(1, 0, 0), Quaternion.identity);
MoveMeshCommand move2 = new MoveMeshCommand(
meshTwo, new Vector3(0, 1, 0), Quaternion.identity);
List<Command> commands = new List<Command>();
commands.Add(move1);
commands.Add(move2);

model.ApplyCommand(new CompositeCommand(commands));

// Check the meshes' new locations.
NUnit.Framework.Assert.Less(
Vector3.Distance(model.GetMesh(meshOne).offset,
new Vector3(1, 0, 0)), 0.001f);
NUnit.Framework.Assert.Less(
Vector3.Distance(model.GetMesh(meshTwo).offset,
new Vector3(1, 2, 1)), 0.001f);

// Undo and make sure they are back.
model.Undo();
NUnit.Framework.Assert.Less(
Vector3.Distance(model.GetMesh(meshOne).offset,
new Vector3(0, 0, 0)), 0.001f);
NUnit.Framework.Assert.Less(
Vector3.Distance(model.GetMesh(meshTwo).offset,
new Vector3(1, 1, 1)), 0.001f);
namespace com.google.apps.peltzer.client.model.core
{

[TestFixture]
// Tests for Command and implementations.
public class CommandTest
{

[Test]
public void TestCompositeMove()
{
int meshOne = 1;
int meshTwo = 2;

Model model = new Model(new Bounds(Vector3.zero, Vector3.one * 10));

// Add two meshes.
model.ApplyCommand(new AddMeshCommand(Primitives.AxisAlignedBox(
meshOne, Vector3.zero, Vector3.one, /* materialId */ 3)));
model.ApplyCommand(new AddMeshCommand(Primitives.AxisAlignedBox(
meshTwo, Vector3.one, Vector3.one, /* materialId */ 4)));

// Check the meshes are where we think they are.
NUnit.Framework.Assert.Less(
Vector3.Distance(model.GetMesh(meshOne).offset,
new Vector3(0, 0, 0)), 0.001f);
NUnit.Framework.Assert.Less(
Vector3.Distance(model.GetMesh(meshTwo).offset,
new Vector3(1, 1, 1)), 0.001f);

// Make and apply a CompositeCommand that moves both of them.
MoveMeshCommand move1 = new MoveMeshCommand(
meshOne, new Vector3(1, 0, 0), Quaternion.identity);
MoveMeshCommand move2 = new MoveMeshCommand(
meshTwo, new Vector3(0, 1, 0), Quaternion.identity);
List<Command> commands = new List<Command>();
commands.Add(move1);
commands.Add(move2);

model.ApplyCommand(new CompositeCommand(commands));

// Check the meshes' new locations.
NUnit.Framework.Assert.Less(
Vector3.Distance(model.GetMesh(meshOne).offset,
new Vector3(1, 0, 0)), 0.001f);
NUnit.Framework.Assert.Less(
Vector3.Distance(model.GetMesh(meshTwo).offset,
new Vector3(1, 2, 1)), 0.001f);

// Undo and make sure they are back.
model.Undo();
NUnit.Framework.Assert.Less(
Vector3.Distance(model.GetMesh(meshOne).offset,
new Vector3(0, 0, 0)), 0.001f);
NUnit.Framework.Assert.Less(
Vector3.Distance(model.GetMesh(meshTwo).offset,
new Vector3(1, 1, 1)), 0.001f);
}

[Test]
public void TestCompositeUndo()
{
int meshOne = 1;

Model model = new Model(new Bounds(Vector3.zero, Vector3.one * 10));

// Add a Mesh.
model.ApplyCommand(new AddMeshCommand(Primitives.AxisAlignedBox(
meshOne, Vector3.zero, Vector3.one, /* materialId */ 3)));

// Create a CompositeCommand that deletes and adds the same mesh.
List<Command> commands = new List<Command>();
commands.Add(new DeleteMeshCommand(meshOne));
commands.Add(new AddMeshCommand(Primitives.AxisAlignedBox(
meshOne, Vector3.zero, Vector3.one, /* materialId */ 3)));

CompositeCommand composite = new CompositeCommand(commands);

CompositeCommand undoCommand =
(CompositeCommand)composite.GetUndoCommand(model);

List<Command> undoList = undoCommand.GetCommands();

// The order of commands should be the same, we invert the commands
// *and* invert the order.
NUnit.Framework.Assert.NotNull(undoList[1] as AddMeshCommand);
NUnit.Framework.Assert.NotNull(undoList[0] as DeleteMeshCommand);
}

[Test]
public void TestRotation()
{
Model model = new Model(new Bounds(Vector3.zero, Vector3.one * 10));

MMesh mesh = Primitives.AxisAlignedBox(1, Vector3.zero, Vector3.one, /* materialId */ 2);
model.AddMesh(mesh);

CheckBounds(model.GetMesh(1).bounds, new Bounds(Vector3.zero, Vector3.one * 2.0f));

MoveMeshCommand cmd = new MoveMeshCommand(1, Vector3.zero, Quaternion.AngleAxis(45, Vector3.up));
model.ApplyCommand(cmd);
// Bounds should have grown, since the box is no longer axis-aligned.
float extends = 2.0f * Mathf.Sqrt(2);
CheckBounds(model.GetMesh(1).bounds, new Bounds(Vector3.zero, new Vector3(extends, 2.0f, extends)));

model.Undo();
// Make sure we are back:
CheckBounds(model.GetMesh(1).bounds, new Bounds(Vector3.zero, Vector3.one * 2.0f));
}

private void CheckBounds(Bounds left, Bounds right)
{
NUnit.Framework.Assert.Less(Vector3.Distance(left.center, right.center), 0.0001);
NUnit.Framework.Assert.Less(Vector3.Distance(left.extents, right.extents), 0.0001);
}

[Test]
public void TestChangeFacePropertiesCommand()
{
Model model = new Model(new Bounds(Vector3.zero, Vector3.one * 10));

int baseMaterialId = 2;
int newMaterial1 = 3;
int newMaterial2 = 4;
MMesh mesh = Primitives.AxisAlignedBox(1, Vector3.zero, Vector3.one, baseMaterialId);
model.AddMesh(mesh);

Dictionary<int, FaceProperties> props = new Dictionary<int, FaceProperties>();
props[1] = new FaceProperties(newMaterial1);
props[2] = new FaceProperties(newMaterial2);

ChangeFacePropertiesCommand command = new ChangeFacePropertiesCommand(1, props);

// Apply the command, ensure the mesh was updated.
model.ApplyCommand(command);
NUnit.Framework.Assert.AreEqual(model.GetMesh(1).GetFace(0).properties.materialId, baseMaterialId);
NUnit.Framework.Assert.AreEqual(model.GetMesh(1).GetFace(1).properties.materialId, newMaterial1);
NUnit.Framework.Assert.AreEqual(model.GetMesh(1).GetFace(2).properties.materialId, newMaterial2);

// Undo, faces should be back to normal.
model.Undo();
NUnit.Framework.Assert.AreEqual(model.GetMesh(1).GetFace(0).properties.materialId, baseMaterialId);
NUnit.Framework.Assert.AreEqual(model.GetMesh(1).GetFace(1).properties.materialId, baseMaterialId);
NUnit.Framework.Assert.AreEqual(model.GetMesh(1).GetFace(2).properties.materialId, baseMaterialId);

// Redo, changes should be applied again.
model.Redo();
NUnit.Framework.Assert.AreEqual(model.GetMesh(1).GetFace(0).properties.materialId, baseMaterialId);
NUnit.Framework.Assert.AreEqual(model.GetMesh(1).GetFace(1).properties.materialId, newMaterial1);
NUnit.Framework.Assert.AreEqual(model.GetMesh(1).GetFace(2).properties.materialId, newMaterial2);
}
}

[Test]
public void TestCompositeUndo() {
int meshOne = 1;

Model model = new Model(new Bounds(Vector3.zero, Vector3.one * 10));

// Add a Mesh.
model.ApplyCommand(new AddMeshCommand(Primitives.AxisAlignedBox(
meshOne, Vector3.zero, Vector3.one, /* materialId */ 3)));

// Create a CompositeCommand that deletes and adds the same mesh.
List<Command> commands = new List<Command>();
commands.Add(new DeleteMeshCommand(meshOne));
commands.Add(new AddMeshCommand(Primitives.AxisAlignedBox(
meshOne, Vector3.zero, Vector3.one, /* materialId */ 3)));

CompositeCommand composite = new CompositeCommand(commands);

CompositeCommand undoCommand =
(CompositeCommand) composite.GetUndoCommand(model);

List<Command> undoList = undoCommand.GetCommands();

// The order of commands should be the same, we invert the commands
// *and* invert the order.
NUnit.Framework.Assert.NotNull(undoList[1] as AddMeshCommand);
NUnit.Framework.Assert.NotNull(undoList[0] as DeleteMeshCommand);
}

[Test]
public void TestRotation() {
Model model = new Model(new Bounds(Vector3.zero, Vector3.one * 10));

MMesh mesh = Primitives.AxisAlignedBox(1, Vector3.zero, Vector3.one, /* materialId */ 2);
model.AddMesh(mesh);

CheckBounds(model.GetMesh(1).bounds, new Bounds(Vector3.zero, Vector3.one * 2.0f));

MoveMeshCommand cmd = new MoveMeshCommand(1, Vector3.zero, Quaternion.AngleAxis(45, Vector3.up));
model.ApplyCommand(cmd);
// Bounds should have grown, since the box is no longer axis-aligned.
float extends = 2.0f * Mathf.Sqrt(2);
CheckBounds(model.GetMesh(1).bounds, new Bounds(Vector3.zero, new Vector3(extends, 2.0f, extends)));

model.Undo();
// Make sure we are back:
CheckBounds(model.GetMesh(1).bounds, new Bounds(Vector3.zero, Vector3.one * 2.0f));
}

private void CheckBounds(Bounds left, Bounds right) {
NUnit.Framework.Assert.Less(Vector3.Distance(left.center, right.center), 0.0001);
NUnit.Framework.Assert.Less(Vector3.Distance(left.extents, right.extents), 0.0001);
}

[Test]
public void TestChangeFacePropertiesCommand() {
Model model = new Model(new Bounds(Vector3.zero, Vector3.one * 10));

int baseMaterialId = 2;
int newMaterial1 = 3;
int newMaterial2 = 4;
MMesh mesh = Primitives.AxisAlignedBox(1, Vector3.zero, Vector3.one, baseMaterialId);
model.AddMesh(mesh);

Dictionary<int, FaceProperties> props = new Dictionary<int, FaceProperties>();
props[1] = new FaceProperties(newMaterial1);
props[2] = new FaceProperties(newMaterial2);

ChangeFacePropertiesCommand command = new ChangeFacePropertiesCommand(1, props);

// Apply the command, ensure the mesh was updated.
model.ApplyCommand(command);
NUnit.Framework.Assert.AreEqual(model.GetMesh(1).GetFace(0).properties.materialId, baseMaterialId);
NUnit.Framework.Assert.AreEqual(model.GetMesh(1).GetFace(1).properties.materialId, newMaterial1);
NUnit.Framework.Assert.AreEqual(model.GetMesh(1).GetFace(2).properties.materialId, newMaterial2);

// Undo, faces should be back to normal.
model.Undo();
NUnit.Framework.Assert.AreEqual(model.GetMesh(1).GetFace(0).properties.materialId, baseMaterialId);
NUnit.Framework.Assert.AreEqual(model.GetMesh(1).GetFace(1).properties.materialId, baseMaterialId);
NUnit.Framework.Assert.AreEqual(model.GetMesh(1).GetFace(2).properties.materialId, baseMaterialId);

// Redo, changes should be applied again.
model.Redo();
NUnit.Framework.Assert.AreEqual(model.GetMesh(1).GetFace(0).properties.materialId, baseMaterialId);
NUnit.Framework.Assert.AreEqual(model.GetMesh(1).GetFace(1).properties.materialId, newMaterial1);
NUnit.Framework.Assert.AreEqual(model.GetMesh(1).GetFace(2).properties.materialId, newMaterial2);
}
}
}
Loading

0 comments on commit 88f74be

Please sign in to comment.