A game about forced loneliness, made by TACStudios
at master 74 lines 4.0 kB view raw
1using System.Collections.Generic; 2using System.Linq; 3using NUnit.Framework; 4 5namespace UnityEngine.Rendering.Tests 6{ 7 class InputRegisteringTests 8 { 9 static TestCaseData[] s_DuplicateTestCaseDatas = 10 { 11 new TestCaseData(new List<InputManagerEntry>() 12 { 13 new() { name = "Another Action 1", kind = InputManagerEntry.Kind.Axis }, 14 new() { name = "Duplicate Action", kind = InputManagerEntry.Kind.Axis }, 15 new() { name = "Another Action 2", kind = InputManagerEntry.Kind.Axis }, 16 new() { name = "Duplicate Action", kind = InputManagerEntry.Kind.Axis }, 17 new() { name = "Duplicate Action", kind = InputManagerEntry.Kind.Axis }, 18 }) 19 .SetName("Given a set containing duplicate entries, when removing duplicate entries, only the first of each duplicate is kept") 20 .Returns(new string[] { "Another Action 1", "Duplicate Action", "Another Action 2" }), 21 new TestCaseData(new List<InputManagerEntry>() 22 { 23 new() { name = "Duplicate Action", kind = InputManagerEntry.Kind.Axis }, 24 new() { name = "Duplicate Action", kind = InputManagerEntry.Kind.Mouse }, 25 }) 26 .SetName("Given entries with duplicate names but different kinds, when removing duplicate entries, both are kept") 27 .Returns(new string[] { "Duplicate Action", "Duplicate Action" }), 28 }; 29 30 [Test, TestCaseSource(nameof(s_DuplicateTestCaseDatas))] 31 public string[] GetEntriesWithoutDuplicates(List<InputManagerEntry> entries) 32 { 33 return InputRegistering.GetEntriesWithoutDuplicates(entries) 34 .Select(e => e.name).ToArray(); 35 } 36 37 static TestCaseData[] s_AlreadyRegisteredTestCaseDatas = 38 { 39 new TestCaseData(new List<InputManagerEntry>() 40 { 41 new() { name = "New Action 1", kind = InputManagerEntry.Kind.Axis }, 42 new() { name = "New Action 2", kind = InputManagerEntry.Kind.Mouse }, 43 new() { name = "Old Action 1", kind = InputManagerEntry.Kind.Axis }, 44 new() { name = "Old Action 2", kind = InputManagerEntry.Kind.Mouse }, 45 }, new List<(string, InputManagerEntry.Kind)>() 46 { 47 ("Old Action 1", InputManagerEntry.Kind.Axis), 48 ("Old Action 2", InputManagerEntry.Kind.Mouse), 49 ("Old Action 3", InputManagerEntry.Kind.Mouse) 50 }) 51 .SetName("Given a set of entries where some of them is already registered, when filtering out already registered entries, they are removed") 52 .Returns(new string[] { "New Action 1", "New Action 2" }), 53 new TestCaseData(new List<InputManagerEntry>() 54 { 55 new() { name = "Old Action 1", kind = InputManagerEntry.Kind.Axis }, 56 new() { name = "Old Action 2", kind = InputManagerEntry.Kind.Mouse }, 57 }, new List<(string, InputManagerEntry.Kind)>() 58 { 59 ("Old Action 1", InputManagerEntry.Kind.Axis), 60 ("Old Action 2", InputManagerEntry.Kind.Axis), 61 }) 62 .SetName("Given an entry with already registered name but different kind, when filtering out already registered entries, only ones with matching kind are removed") 63 .Returns(new string[] { "Old Action 2" }), 64 }; 65 66 67 [Test, TestCaseSource(nameof(s_AlreadyRegisteredTestCaseDatas))] 68 public string[] GetEntriesWithoutAlreadyRegistered(List<InputManagerEntry> entries, List<(string, InputManagerEntry.Kind)> cachedEntries) 69 { 70 return InputRegistering.GetEntriesWithoutAlreadyRegistered(entries, cachedEntries) 71 .Select(e => e.name).ToArray(); 72 } 73 } 74}