public void Clone() { TimingGroup first = new TimingGroup(); TimingGroup second = first.Clone(); Assert.AreEqual(first, second); }
public void FromStartTillEndWithSingleBase() { var owner = new Mock <IIntervalOwner>(); { owner.Setup(o => o.CurrentTicks) .Returns(10L); } var group = new TimingGroup(); var parents = new ITimerInterval[] { new TimerInterval(owner.Object, group, "a"), }; var children = new[] { new ITimerInterval[] { new TimerInterval(owner.Object, group, "aa"), new TimerInterval(owner.Object, group, "ab"), new TimerInterval(owner.Object, group, "ac"), }, }; var storage = BuildStorage(parents, children); var report = storage.FromStartTillEnd(); CheckReport(report, parents, children); CleanUpIntervals(parents, children); }
public void CompareToWithNullObject() { TimingGroup first = new TimingGroup(); object second = null; Assert.AreEqual(1, first.CompareTo(second)); }
public void AddBaseInterval() { var tree = new TimingTree(); var owner = new Mock <IIntervalOwner>(); { owner.Setup(o => o.CurrentTicks) .Returns(10L); } var group = new TimingGroup(); using (var interval = new TimerInterval(owner.Object, group, "a")) { interval.Start(); tree.AddBaseInterval(interval); Assert.That( tree.BaseIntervals(group), Is.EquivalentTo( new ITimerInterval[] { interval })); } }
public void SmallerThanOperatorWithBothObjectsNull() { TimingGroup first = null; TimingGroup second = null; Assert.IsFalse(first < second); }
public void SmallerThanOperatorWithEqualObjects() { var first = new TimingGroup(); var second = first.Clone(); Assert.IsFalse(first < second); }
public void SmallerThanOperatorWithFirstObjectNull() { TimingGroup first = null; TimingGroup second = new TimingGroup(); Assert.IsTrue(first < second); }
public void SmallerThanOperatorWithSecondObjectNull() { TimingGroup first = new TimingGroup(); TimingGroup second = null; Assert.IsFalse(first < second); }
public void LargerThanOperatorWithSecondObjectNull() { TimingGroup first = new TimingGroup(); TimingGroup second = null; Assert.IsTrue(first > second); }
public void LargerThanOperatorWithFirstObjectNull() { TimingGroup first = null; TimingGroup second = new TimingGroup(); Assert.IsFalse(first > second); }
public void MeasureWithMultipleGroups() { ITimerInterval storedInterval = null; var storage = new Mock <IStoreIntervals>(); { storage.Setup(r => r.AddBaseInterval(It.IsAny <ITimerInterval>())) .Callback <ITimerInterval>(i => storedInterval = i); } var profiler = new Profiler(storage.Object); var description = "description"; for (int i = 0; i < 10; i++) { var group = new TimingGroup(); var interval = profiler.MeasureInterval(group, description); using (interval) { Thread.Sleep(10); } Assert.AreSame(interval, storedInterval); storage.Verify(r => r.AddChildInterval(It.IsAny <ITimerInterval>(), It.IsAny <ITimerInterval>()), Times.Never()); } }
public void CompareToWithUnequalObjectTypes() { TimingGroup first = new TimingGroup(); object second = new object(); Assert.Throws <ArgumentException>(() => first.CompareTo(second)); }
public void CompareToOperatorWithEqualObjects() { var first = new TimingGroup(); object second = first.Clone(); Assert.AreEqual(0, first.CompareTo(second)); }
private void DoToolbar() { using (new EditorGUILayout.HorizontalScope(Styles.toolbar)) { var selectedIndex = EditorGUILayout.Popup(Array.IndexOf(timingFiles, selectedFile), timingNames, Styles.toolbarDropDown); if (selectedIndex >= 0 && selectedIndex < timingFiles.Length) { selectedFile = timingFiles[selectedIndex]; loadedFile = null; } GUILayout.FlexibleSpace(); if (GUILayout.Button("Open Timings Folder", Styles.toolbarButton)) { EditorUtility.RevealInFinder(Timing.TimingsSaveFolder); } GUILayout.Space(7f); GUI.enabled = !string.IsNullOrEmpty(selectedFile); if (GUILayout.Button("Delete File", Styles.toolbarButton)) { File.Delete(selectedFile); File.Delete(selectedFile + ".meta"); selectedFile = timingFiles.LastOrDefault(); loadedFile = null; } GUI.enabled = loadedFile != null; if (GUILayout.Button("Save File", Styles.toolbarButton)) { var path = EditorUtility.SaveFilePanel("Save timing file", Timing.TimingsSaveFolder, "New Timing", "timing"); if (!string.IsNullOrEmpty(path)) { loadedFile.Save(path); } } GUI.enabled = true; if (GUILayout.Button("Load File", Styles.toolbarButton)) { var path = EditorUtility.OpenFilePanel("Select timing file", Timing.TimingsSaveFolder, "timing"); if (!string.IsNullOrEmpty(path)) { selectedFile = path; loadedFile = null; } } } }
public void CopyTreeCompletely() { var owner = new Mock <IIntervalOwner>(); { owner.Setup(o => o.CurrentTicks) .Returns(10L); } var group = new TimingGroup(); var parents = new ITimerInterval[] { new TimerInterval(owner.Object, group, "a"), new TimerInterval(owner.Object, group, "b"), new TimerInterval(owner.Object, group, "c"), }; var children = new[] { new ITimerInterval[] { new TimerInterval(owner.Object, group, "aa"), new TimerInterval(owner.Object, group, "ab"), new TimerInterval(owner.Object, group, "ac"), }, new ITimerInterval[] { new TimerInterval(owner.Object, group, "ba"), new TimerInterval(owner.Object, group, "bb"), new TimerInterval(owner.Object, group, "bc"), }, new ITimerInterval[] { new TimerInterval(owner.Object, group, "ca"), new TimerInterval(owner.Object, group, "cb"), new TimerInterval(owner.Object, group, "cc"), }, }; var tree = BuildTree(parents, children); var otherTree = new TimingTree(tree); Assert.That(otherTree.BaseIntervals(group), Is.EquivalentTo(parents)); Assert.That(otherTree.ChildIntervals(parents[0]), Is.EquivalentTo(children[0])); Assert.That(otherTree.ChildIntervals(parents[1]), Is.EquivalentTo(children[1])); Assert.That(otherTree.ChildIntervals(parents[2]), Is.EquivalentTo(children[2])); CleanUpIntervals(parents, children); }
public void MeasureNested() { var timers = new List <Tuple <ITimerInterval, int> >(); var storage = new Mock <IStoreIntervals>(); { storage.Setup(r => r.AddBaseInterval(It.IsAny <ITimerInterval>())) .Callback <ITimerInterval>(i => timers.Add(new Tuple <ITimerInterval, int>(i, 0))); storage.Setup(r => r.AddChildInterval(It.IsAny <ITimerInterval>(), It.IsAny <ITimerInterval>())) .Callback <ITimerInterval, ITimerInterval>( (parent, child) => { var storedParent = timers.Find(t => ReferenceEquals(t.Item1, parent)); timers.Add(new Tuple <ITimerInterval, int>(child, storedParent.Item2 + 1)); }); } var profiler = new Profiler(storage.Object); var description = "description"; var group = new TimingGroup(); ITimerInterval topLevelInterval; ITimerInterval firstChild; ITimerInterval secondChild; using (topLevelInterval = profiler.MeasureInterval(group, description)) { using (firstChild = profiler.MeasureInterval(group, string.Empty)) { Thread.Sleep(10); } using (secondChild = profiler.MeasureInterval(group, string.Empty)) { Thread.Sleep(10); } } Assert.That( timers, Is.EquivalentTo( new[] { new Tuple <ITimerInterval, int>(topLevelInterval, 0), new Tuple <ITimerInterval, int>(firstChild, 1), new Tuple <ITimerInterval, int>(secondChild, 1), })); }
public void ForInterval() { var owner = new Mock <IIntervalOwner>(); { owner.Setup(o => o.CurrentTicks) .Returns(10L); } var group = new TimingGroup(); var parents = new ITimerInterval[] { new TimerInterval(owner.Object, group, "a"), new TimerInterval(owner.Object, group, "b"), new TimerInterval(owner.Object, group, "c"), }; var children = new[] { new ITimerInterval[] { new TimerInterval(owner.Object, group, "aa"), new TimerInterval(owner.Object, group, "ab"), new TimerInterval(owner.Object, group, "ac"), }, new ITimerInterval[] { new TimerInterval(owner.Object, group, "ba"), new TimerInterval(owner.Object, group, "bb"), new TimerInterval(owner.Object, group, "bc"), }, new ITimerInterval[] { new TimerInterval(owner.Object, group, "ca"), new TimerInterval(owner.Object, group, "cb"), new TimerInterval(owner.Object, group, "cc"), }, }; var storage = BuildStorage(parents, children); var report = storage.ForInterval(parents[1]); CheckReport(report, new[] { parents[1] }, new[] { children[1] }); CleanUpIntervals(parents, children); }
public void TraversePreOrderWithSingleRoot() { var owner = new Mock <IIntervalOwner>(); { owner.Setup(o => o.CurrentTicks) .Returns(10L); } var group = new TimingGroup(); var parents = new ITimerInterval[] { new TimerInterval(owner.Object, group, "a"), }; var children = new[] { new ITimerInterval[] { new TimerInterval(owner.Object, group, "aa"), new TimerInterval(owner.Object, group, "ab"), new TimerInterval(owner.Object, group, "ac"), }, }; var tree = BuildTree(parents, children); var list = new List <Tuple <ITimerInterval, int> >(); tree.TraversePreOrder((node, level) => list.Add(new Tuple <ITimerInterval, int>(node, level))); Assert.AreEqual(parents[0], list[0].Item1); Assert.AreEqual(0, list[0].Item2); Assert.AreEqual(children[0][0], list[1].Item1); Assert.AreEqual(1, list[1].Item2); Assert.AreEqual(children[0][1], list[2].Item1); Assert.AreEqual(1, list[2].Item2); Assert.AreEqual(children[0][2], list[3].Item1); Assert.AreEqual(1, list[3].Item2); CleanUpIntervals(parents, children); }
public void ToReport() { var group = new TimingGroup(); var description = "description"; var ticks = 10L; var interval = new Mock <ITimerInterval>(); { interval.Setup(i => i.Group) .Returns(group); interval.Setup(i => i.Description) .Returns(description); interval.Setup(i => i.TotalTicks) .Returns(ticks); } var path = TempFile(); Func <Stream> builder = () => new FileStream(path, FileMode.Create, FileAccess.Write); var reporter = new TextReporter(builder); var tree = new TimingTree(); tree.AddBaseInterval(interval.Object); var report = new TimingReport(tree); reporter.Transform(report); using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read)) { var result = FromStream(stream); Assert.AreEqual( string.Format( CultureInfo.CurrentCulture, "Description Total time (ms)" + Environment.NewLine + "{0} {1}" + Environment.NewLine, description, ticks / 10000), result); } }
private void OnGUI() { DoToolbar(); DoHeader(); if (!File.Exists(selectedFile) && loadedFile == null) { return; } try { if (loadedFile == null) { loadedFile = new TimingGroup(selectedFile); } } catch (Exception e) { EditorGUILayout.HelpBox(e.ToString(), MessageType.Error, true); } DoTimingSampleList(); DoFooter(); }
public void UpdateTimingGroupOptions() { List <Dropdown.OptionData> options = new List <Dropdown.OptionData>(); options.Add(new Dropdown.OptionData { text = "默认" }); foreach (var tg in ArcTimingManager.Instance.timingGroups) { options.Add(new Dropdown.OptionData { text = tg.Id.ToString() }); } TimingGroup.GetComponentInChildren <Dropdown>().options = options; List <ArcNote> selected = AdeCursorManager.Instance.SelectedNotes; int count = selected.Count; if (TimingGroup.gameObject.activeSelf && count > 0) { bool multiple = count != 1; ArcNote note = selected[0]; TimingGroup.GetComponentInChildren <Dropdown>().SetValueWithoutNotify(multiple ? 0 : ((note as IHasTimingGroup).TimingGroup?.Id ?? 0)); } }
public void AddChildInterval() { var tree = new TimingTree(); var owner = new Mock <IIntervalOwner>(); { owner.Setup(o => o.CurrentTicks) .Returns(10L); } var group = new TimingGroup(); using (var parent = new TimerInterval(owner.Object, group, "a")) { parent.Start(); tree.AddBaseInterval(parent); using (var child = new TimerInterval(owner.Object, group, "b")) { child.Start(); tree.AddChildInterval(parent, child); Assert.That(tree.ChildIntervals(parent), Is.EquivalentTo(new ITimerInterval[] { child })); } } }
public void ToReportWithMultiLevelIntervals() { var ticks = 10L; var group = new TimingGroup(); var parent = new Mock <ITimerInterval>(); { parent.Setup(i => i.Group) .Returns(group); parent.Setup(i => i.Description) .Returns("parent"); parent.Setup(i => i.TotalTicks) .Returns(ticks); } var child1 = new Mock <ITimerInterval>(); { child1.Setup(i => i.Group) .Returns(group); child1.Setup(i => i.Description) .Returns("child1"); child1.Setup(i => i.TotalTicks) .Returns(ticks); } var child2 = new Mock <ITimerInterval>(); { child2.Setup(i => i.Group) .Returns(group); child2.Setup(i => i.Description) .Returns("child2"); child2.Setup(i => i.TotalTicks) .Returns(ticks); } var path = TempFile(); Func <Stream> builder = () => new FileStream(path, FileMode.Create, FileAccess.Write); var reporter = new TextReporter(builder); var tree = new TimingTree(); tree.AddBaseInterval(parent.Object); tree.AddChildInterval(parent.Object, child1.Object); tree.AddChildInterval(parent.Object, child2.Object); var report = new TimingReport(tree); reporter.Transform(report); using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read)) { var result = FromStream(stream); var textBuilder = new StringBuilder(); { textBuilder.AppendLine("Description Total time (ms)"); textBuilder.AppendLine( string.Format( CultureInfo.CurrentCulture, "{0} {1}", parent.Object.Description, ticks / 10000)); textBuilder.AppendLine( string.Format( CultureInfo.CurrentCulture, " {0} {1}", child1.Object.Description, ticks / 10000)); textBuilder.AppendLine( string.Format( CultureInfo.CurrentCulture, " {0} {1}", child2.Object.Description, ticks / 10000)); } Assert.AreEqual(textBuilder.ToString(), result); } }
private void MakeupFields() { List <ArcNote> selected = AdeCursorManager.Instance.SelectedNotes; int count = selected.Count; if (count == 0) { Panel.gameObject.SetActive(false); return; } else { SelectParent.gameObject.SetActive(false); if (count == 1) { if (selected[0] is ArcArcTap) { SelectParent.gameObject.SetActive(true); } } Timing.gameObject.SetActive(true); Track.gameObject.SetActive(true); EndTiming.gameObject.SetActive(true); StartPos.gameObject.SetActive(true); EndPos.gameObject.SetActive(true); LineType.gameObject.SetActive(true); Color.gameObject.SetActive(true); IsVoid.gameObject.SetActive(true); TimingGroup.gameObject.SetActive(true); foreach (var s in selected) { if (Track.gameObject.activeSelf) { Track.gameObject.SetActive(s is ArcTap || s is ArcHold); } if (EndTiming.gameObject.activeSelf) { EndTiming.gameObject.SetActive(s is ArcLongNote); } if (StartPos.gameObject.activeSelf) { StartPos.gameObject.SetActive(s is ArcArc); } if (EndPos.gameObject.activeSelf) { EndPos.gameObject.SetActive(s is ArcArc); } if (LineType.gameObject.activeSelf) { LineType.gameObject.SetActive(s is ArcArc); } if (Color.gameObject.activeSelf) { Color.gameObject.SetActive(s is ArcArc); } if (IsVoid.gameObject.activeSelf) { IsVoid.gameObject.SetActive(s is ArcArc); } if (TimingGroup.gameObject.activeSelf) { TimingGroup.gameObject.SetActive(s is ISetableTimingGroup); } } bool multiple = count != 1; ArcNote note = selected[0]; Timing.GetComponentInChildren <InputField>().SetTextWithoutNotify(multiple ? "-" : note.Timing.ToString()); if (Track.gameObject.activeSelf) { Track.GetComponentInChildren <InputField>().SetTextWithoutNotify(multiple ? "-" : (note is ArcTap ? (note as ArcTap).Track.ToString() : (note as ArcHold).Track.ToString())); } if (EndTiming.gameObject.activeSelf) { EndTiming.GetComponentInChildren <InputField>().SetTextWithoutNotify(multiple ? "-" : (note as ArcLongNote).EndTiming.ToString()); } if (StartPos.gameObject.activeSelf) { StartPos.GetComponentInChildren <InputField>().SetTextWithoutNotify(multiple ? "-,-" : $"{(note as ArcArc).XStart.ToString("f2")},{(note as ArcArc).YStart.ToString("f2")}"); } if (EndPos.gameObject.activeSelf) { EndPos.GetComponentInChildren <InputField>().SetTextWithoutNotify(multiple ? "-,-" : $"{(note as ArcArc).XEnd.ToString("f2")},{(note as ArcArc).YEnd.ToString("f2")}"); } if (LineType.gameObject.activeSelf) { LineType.GetComponentInChildren <Dropdown>().SetValueWithoutNotify(multiple ? 0 : (int)(note as ArcArc).LineType); } if (Color.gameObject.activeSelf) { Color.GetComponentInChildren <Dropdown>().SetValueWithoutNotify(multiple ? 0 : (note as ArcArc).Color); } if (IsVoid.gameObject.activeSelf) { IsVoid.GetComponentInChildren <Toggle>().SetIsOnWithoutNotify(multiple ? false : (note as ArcArc).IsVoid); } if (TimingGroup.gameObject.activeSelf) { TimingGroup.GetComponentInChildren <Dropdown>().SetValueWithoutNotify(multiple ? 0 : ((note as IHasTimingGroup).TimingGroup?.Id ?? 0)); } Panel.gameObject.SetActive(true); } }
private void SetCurrentTimingGroup(TimingGroup group) { loadedFile = group; selectedFile = "Last Timing"; }
public void TraversePreOrderWithMultipleGroups() { var owner = new Mock <IIntervalOwner>(); { owner.Setup(o => o.CurrentTicks) .Returns(10L); } var firstGroup = new TimingGroup(); var secondGroup = new TimingGroup(); var thirdGroup = new TimingGroup(); var parents = new ITimerInterval[] { new TimerInterval(owner.Object, firstGroup, "a"), new TimerInterval(owner.Object, secondGroup, "b"), new TimerInterval(owner.Object, thirdGroup, "c"), }; var children = new[] { new ITimerInterval[] { new TimerInterval(owner.Object, firstGroup, "aa"), new TimerInterval(owner.Object, firstGroup, "ab"), new TimerInterval(owner.Object, firstGroup, "ac"), }, new ITimerInterval[] { new TimerInterval(owner.Object, secondGroup, "ba"), new TimerInterval(owner.Object, secondGroup, "bb"), new TimerInterval(owner.Object, secondGroup, "bc"), }, new ITimerInterval[] { new TimerInterval(owner.Object, thirdGroup, "ca"), new TimerInterval(owner.Object, thirdGroup, "cb"), new TimerInterval(owner.Object, thirdGroup, "cc"), }, }; var tree = BuildTree(parents, children); var firstList = new List <Tuple <ITimerInterval, int> >(); tree.TraversePreOrder(firstGroup, (node, level) => firstList.Add(new Tuple <ITimerInterval, int>(node, level))); Assert.AreEqual(parents[0], firstList[0].Item1); Assert.AreEqual(0, firstList[0].Item2); Assert.AreEqual(children[0][0], firstList[1].Item1); Assert.AreEqual(1, firstList[1].Item2); Assert.AreEqual(children[0][1], firstList[2].Item1); Assert.AreEqual(1, firstList[2].Item2); Assert.AreEqual(children[0][2], firstList[3].Item1); Assert.AreEqual(1, firstList[3].Item2); var secondList = new List <Tuple <ITimerInterval, int> >(); tree.TraversePreOrder(secondGroup, (node, level) => secondList.Add(new Tuple <ITimerInterval, int>(node, level))); Assert.AreEqual(parents[1], secondList[0].Item1); Assert.AreEqual(0, secondList[0].Item2); Assert.AreEqual(children[1][0], secondList[1].Item1); Assert.AreEqual(1, secondList[1].Item2); Assert.AreEqual(children[1][1], secondList[2].Item1); Assert.AreEqual(1, secondList[2].Item2); Assert.AreEqual(children[1][2], secondList[3].Item1); Assert.AreEqual(1, secondList[3].Item2); var thirdList = new List <Tuple <ITimerInterval, int> >(); tree.TraversePreOrder(thirdGroup, (node, level) => thirdList.Add(new Tuple <ITimerInterval, int>(node, level))); Assert.AreEqual(parents[2], thirdList[0].Item1); Assert.AreEqual(0, thirdList[0].Item2); Assert.AreEqual(children[2][0], thirdList[1].Item1); Assert.AreEqual(1, thirdList[1].Item2); Assert.AreEqual(children[2][1], thirdList[2].Item1); Assert.AreEqual(1, thirdList[2].Item2); Assert.AreEqual(children[2][2], thirdList[3].Item1); Assert.AreEqual(1, thirdList[3].Item2); CleanUpIntervals(parents, children); }