From b2993028499dd994caf5e2a5bf362f3116416ae6 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Wed, 4 Sep 2019 22:33:46 +0300 Subject: Finished implementation and cleanup of Monitor.cs, implimented Wave.cs and added a project for testing --- Oscilloscope/Oscilloscope.sln | 6 ++ Oscilloscope/Oscilloscope/Oscilloscope.csproj | 1 + Oscilloscope/Oscilloscope/Program.cs | 6 +- Oscilloscope/Oscilloscope/Screen.cs | 108 +++++++++++---------- Oscilloscope/Oscilloscope/Wave.cs | 52 ++++++++++ .../OscilloscopeTests/OscilloscopeTests.csproj | 17 ++++ Oscilloscope/OscilloscopeTests/WaveTests.cs | 12 +++ 7 files changed, 146 insertions(+), 56 deletions(-) create mode 100644 Oscilloscope/Oscilloscope/Wave.cs create mode 100644 Oscilloscope/OscilloscopeTests/OscilloscopeTests.csproj create mode 100644 Oscilloscope/OscilloscopeTests/WaveTests.cs (limited to 'Oscilloscope') diff --git a/Oscilloscope/Oscilloscope.sln b/Oscilloscope/Oscilloscope.sln index 2482a4c..c5593af 100644 --- a/Oscilloscope/Oscilloscope.sln +++ b/Oscilloscope/Oscilloscope.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 16.0.29102.190 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Oscilloscope", "Oscilloscope\Oscilloscope.csproj", "{36E3F0B2-B785-4AF3-B59F-483FDA57672A}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OscilloscopeTests", "OscilloscopeTests\OscilloscopeTests.csproj", "{C1898213-07A3-4E50-B164-57E0673ABDED}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +17,10 @@ Global {36E3F0B2-B785-4AF3-B59F-483FDA57672A}.Debug|Any CPU.Build.0 = Debug|Any CPU {36E3F0B2-B785-4AF3-B59F-483FDA57672A}.Release|Any CPU.ActiveCfg = Release|Any CPU {36E3F0B2-B785-4AF3-B59F-483FDA57672A}.Release|Any CPU.Build.0 = Release|Any CPU + {C1898213-07A3-4E50-B164-57E0673ABDED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C1898213-07A3-4E50-B164-57E0673ABDED}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C1898213-07A3-4E50-B164-57E0673ABDED}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C1898213-07A3-4E50-B164-57E0673ABDED}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Oscilloscope/Oscilloscope/Oscilloscope.csproj b/Oscilloscope/Oscilloscope/Oscilloscope.csproj index de6a2a2..1988ba1 100644 --- a/Oscilloscope/Oscilloscope/Oscilloscope.csproj +++ b/Oscilloscope/Oscilloscope/Oscilloscope.csproj @@ -47,6 +47,7 @@ + diff --git a/Oscilloscope/Oscilloscope/Program.cs b/Oscilloscope/Oscilloscope/Program.cs index ea91a62..63c5b1a 100644 --- a/Oscilloscope/Oscilloscope/Program.cs +++ b/Oscilloscope/Oscilloscope/Program.cs @@ -9,16 +9,16 @@ namespace Oscilloscope { class Program { - public static double Fps = 100; + public static double Fps = 30; static void Main(string[] args) { Screen.SetDefaults(); + var triangle = new Wave(new List() { 5, 6, 7, 8, 9, 10, 11, 12}); while (true) { - Screen.DEMO(); + Screen.Measure(triangle.GetValue()); Screen.Print(); - if (Console.KeyAvailable) { Command.Do(); diff --git a/Oscilloscope/Oscilloscope/Screen.cs b/Oscilloscope/Oscilloscope/Screen.cs index 1b04f4d..7b0b388 100644 --- a/Oscilloscope/Oscilloscope/Screen.cs +++ b/Oscilloscope/Oscilloscope/Screen.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace Oscilloscope { - class Screen + public class Screen { public static int Height { get; private set; } public static int Width { get; private set; } @@ -15,9 +15,14 @@ namespace Oscilloscope public static char VerWall { get; private set; } public static char HorWall { get; private set; } - public static char Ray { get; private set; } - public static int RayXPos { get; set; } - public static int RayYPos { get; set; } + public static char RayX { get; private set; } + public static char RayY { get; private set; } + + public static int RayXPos { get; private set; } + public static int RayYPos { get; private set; } //it is used only in xy mode + + private static int Time { get; set; } + private static StringBuilder[] map; public static void SetDefaults() { Height = 10; @@ -26,12 +31,21 @@ namespace Oscilloscope VerWall = '|'; HorWall = '-'; - Ray = '*'; + RayX = '*'; + RayY = '+'; RayXPos = Width / 2; RayYPos = Height / 2; + GenerateMap(); + } + + private static void GenerateMap() { map = new StringBuilder[Height + 2]; - for (int i = 0; i < map.Length; i++) { + + map[0] = new StringBuilder(new string(HorWall, Width + 2)); + map[map.Length - 1] = new StringBuilder(new string(HorWall, Width + 2)); + + for (int i = 1; i < map.Length - 1; i++) { map[i] = new StringBuilder(new string(' ', Width + 2)); } } @@ -42,10 +56,13 @@ namespace Oscilloscope switch (command[0]) { case "size": Height = int.Parse(command[1]); Width = int.Parse(command[2]); + GenerateMap(); break; case "char": - if (command[1] == "ray") Ray = command[2][0]; - //TODO: add other chars + if (command[1] == "x") RayX = command[2][0]; + else if (command[1] == "y") RayY = command[2][0]; + else if (command[1] == "vwall") VerWall = command[2][0]; + else if (command[1] == "hwall") HorWall = command[2][0]; break; } } catch (Exception) { @@ -54,68 +71,53 @@ namespace Oscilloscope } } - private static StringBuilder[] map; + public static void Measure(int valueX) { + RayXPos = valueX; + } + + public static void Measure(int valueX, int valueY) { + RayYPos = valueY; + } public static void Print() { - map[0] = new StringBuilder(new string(HorWall, Width + 2)); - map[map.Length - 1] = new StringBuilder(new string(HorWall, Width + 2)); + CalculateFrame(); + PrintMap(); + } + + private static void CalculateFrame() { for (int row = 1; row < Height; row++) { var currRow = map[row]; - for (int col = 0; col < Width; col++) { + currRow[0] = VerWall; currRow[Width + 1] = VerWall; - if (row == RayYPos && col == RayXPos) { - currRow[col] = Ray; + if (row == RayXPos) { + CleanColumn(Time); - for (int j = 1; j < Height + 1; j++) { - if (j != row) map[j][col] = ' '; - } - } - } + currRow[Time] = RayX; - currRow[0] = VerWall; currRow[Width - 1] = VerWall; + IncrementTime(); + } map[row] = currRow; } + } - PrintMap(); + private static void CleanColumn(int valueCol) { + for (int i = 1; i < map.Length - 2; i++) { + map[i][valueCol] = ' '; + } + } + + private static void IncrementTime() + { + if (Time == Width) Time = 1; + else Time++; } private static void PrintMap() { for (int i = 0; i < map.Length; i++) { Console.WriteLine(map[i]); } - } - - private static int t; - private static int val; - public static void DEMO() { - switch (val) { - case 0: RayYPos = 5; break; - case 1: RayYPos = 4; break; - case 2: RayYPos = 3; break; - case 3: RayYPos = 2; break; - case 4: RayYPos = 1; break; - case 5: RayYPos = 0; break; - case 6: RayYPos = 1; break; - case 7: RayYPos = 2; break; - case 8: RayYPos = 3; break; - case 9: RayYPos = 4; break; - case 10: RayYPos = 5; break; - case 11: RayYPos = 6; break; - case 12: RayYPos = 7; break; - case 13: RayYPos = 8; break; - case 14: RayYPos = 9; break; - case 15: RayYPos = 8; break; - case 16: RayYPos = 7; break; - case 17: RayYPos = 6; val = -1; break; - } - val++; - - if (t == Width) t = 0; - else t++; - - RayXPos = t; - } + } } } diff --git a/Oscilloscope/Oscilloscope/Wave.cs b/Oscilloscope/Oscilloscope/Wave.cs new file mode 100644 index 0000000..6ca5b6f --- /dev/null +++ b/Oscilloscope/Oscilloscope/Wave.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Oscilloscope +{ + public class Wave + { + private static int waveCount = 0; + + private string name; + + private List PeriodValues { get; set; } //a period is compiled of all the values that don't repeat, periods are put next to one another to form the whole wave ; they are the base of the wave + private int CurrValue { get; set; } + + public Wave() : this($"Wave{++waveCount}", new List()) + { } + + public Wave(string name) : this(name, new List()) + { } + + public Wave(List periodValues) :this($"Wave{++waveCount}", periodValues) + { } + + public Wave(string name, List periodValues) { + this.Name = name; + this.PeriodValues = periodValues; + + this.CurrValue = 0; + waveCount++; + } + + public int GetValue() { + if (CurrValue == PeriodValues.Count()) CurrValue = 0; + + return PeriodValues[CurrValue++]; + } + + public string Name { + get { return this.name; } + set { + if (name == "") { + throw new ArgumentException("Name cannot be emty string!"); + } + + name = value; + } + } + } +} diff --git a/Oscilloscope/OscilloscopeTests/OscilloscopeTests.csproj b/Oscilloscope/OscilloscopeTests/OscilloscopeTests.csproj new file mode 100644 index 0000000..7676db9 --- /dev/null +++ b/Oscilloscope/OscilloscopeTests/OscilloscopeTests.csproj @@ -0,0 +1,17 @@ + + + + netcoreapp2.1 + + + + + + + + + + + + + diff --git a/Oscilloscope/OscilloscopeTests/WaveTests.cs b/Oscilloscope/OscilloscopeTests/WaveTests.cs new file mode 100644 index 0000000..aae4f17 --- /dev/null +++ b/Oscilloscope/OscilloscopeTests/WaveTests.cs @@ -0,0 +1,12 @@ +using System; +using System.Linq; +using Oscilloscope; +using NUnit.Framework; +using System.Collections.Generic; + +namespace OscilloscopeTests { + [TestFixture] + public class WaveTests { + + } +} -- cgit v1.2.3