Roses/Assets/Scripts/Tests/KeySequenceTests.cs
2024-04-16 17:55:13 +02:00

101 lines
No EOL
2.4 KiB
C#

using System.Collections.Generic;
using Domain;
using NUnit.Framework;
public class KeySequenceTests {
[Test]
public void NoPresses_DontContain() {
List<int> sequence = new() { 0x1, 0x2, 0x3 };
KeyHistory history = new();
Assert.IsFalse(history.ContainsSequence(sequence));
}
[Test]
public void CorrectPresses_Contains() {
List<int> sequence = new() { 0x1, 0x2, 0x3 };
KeyHistory history = new();
history.KeyPressed(0x1);
history.KeyPressed(0x2);
history.KeyPressed(0x3);
Assert.IsTrue(history.ContainsSequence(sequence));
}
[Test]
public void CorrectPresses_BeforeLast_DontContain() {
List<int> sequence = new() { 0x1, 0x2, 0x3 };
KeyHistory history = new();
history.KeyPressed(0x1);
history.KeyPressed(0x2);
history.KeyPressed(0x3);
history.KeyPressed(0x1);
Assert.IsFalse(history.ContainsSequence(sequence));
}
[Test]
public void IncorrectPresses_DontContain() {
List<int> sequence = new() { 0x1, 0x2, 0x3 };
KeyHistory history = new();
history.KeyPressed(0x1);
history.KeyPressed(0x3);
history.KeyPressed(0x2);
Assert.IsFalse(history.ContainsSequence(sequence));
}
[Test]
public void BeginsWithSpecial_MustContain_Contains() {
List<int> sequence = new() { 0x1, 0x2, 0x3 };
KeyHistory history = new();
history.KeyPressed(0x5, true);
history.KeyPressed(0x1);
history.KeyPressed(0x2);
history.KeyPressed(0x3);
Assert.IsTrue(history.ContainsSequence(sequence, 0x5, true));
}
[Test]
public void DoesntBeginWithSpecial_MustContain_DontContain() {
List<int> sequence = new() { 0x1, 0x2, 0x3 };
KeyHistory history = new();
history.KeyPressed(0x1);
history.KeyPressed(0x1);
history.KeyPressed(0x2);
history.KeyPressed(0x3);
Assert.IsFalse(history.ContainsSequence(sequence, 0x5, true));
}
[Test]
public void BeginsWithSpecial_MustntContain_DontContain() {
List<int> sequence = new() { 0x1, 0x2, 0x3 };
KeyHistory history = new();
history.KeyPressed(0x5, true);
history.KeyPressed(0x1);
history.KeyPressed(0x2);
history.KeyPressed(0x3);
Assert.IsFalse(history.ContainsSequence(sequence, 0x5, false));
}
[Test]
public void DoesntBeginWithSpecial_MustntContain_Contains() {
List<int> sequence = new() { 0x1, 0x2, 0x3 };
KeyHistory history = new();
history.KeyPressed(0x1);
history.KeyPressed(0x2);
history.KeyPressed(0x3);
Assert.IsTrue(history.ContainsSequence(sequence, 0x5, false));
}
}