Skip to content

Commit f1934ea

Browse files
committed
Minor linting
1 parent ff7b443 commit f1934ea

File tree

4 files changed

+43
-45
lines changed

4 files changed

+43
-45
lines changed

AsciiChart.Sharp.TestApp/Program.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33

44
namespace AsciiChart.Sharp.TestApp
55
{
6-
class Program
6+
static class Program
77
{
8-
static void Main(string[] args)
8+
static void Main()
99
{
1010
var series = new double[100];
1111
for (var i = 0; i < series.Length; i++)
1212
{
13-
series[i] = 15 * Math.Sin(i * ((Math.PI * 4) / series.Length));
13+
series[i] = 15 * Math.Sin(i * (Math.PI * 4 / series.Length));
1414
}
15-
15+
1616
Console.OutputEncoding = Encoding.UTF8;
1717
Console.WriteLine(AsciiChart.Plot(series));
1818

@@ -24,18 +24,17 @@ static void Main(string[] args)
2424
AxisLabelRightMargin = 0,
2525
Height = 4,
2626
Fill = '·',
27-
AxisLabelFormat = "0,000.000",
27+
AxisLabelFormat = "0,000.000"
2828
}));
29-
30-
29+
3130
var series2 = new double[100];
3231
for (var i = 0; i < series.Length; i++)
3332
{
34-
series2[i] = (200000 * Math.Cos(i * ((Math.PI * 8) / series.Length))) + 1000000;
33+
series2[i] = 200000 * Math.Cos(i * (Math.PI * 8 / series.Length)) + 1000000;
3534
}
36-
35+
3736
Console.WriteLine();
3837
Console.WriteLine(AsciiChart.Plot(series2, new Options{Height = 10}));
3938
}
4039
}
41-
}
40+
}

AsciiChart.Sharp.Tests/Tests.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace AsciiChart.Sharp.Tests
66
{
77
public class Tests
88
{
9-
private static readonly Regex _normalize = new Regex(@" *(\r\n|\n\r|\n|\r)", RegexOptions.Compiled);
9+
static readonly Regex _normalize = new Regex(@" *(\r\n|\n\r|\n|\r)", RegexOptions.Compiled);
1010

1111
[Test]
1212
[TestCaseSource(nameof(Cases))]
@@ -16,9 +16,9 @@ public void TestPlot(double[] series, Options opts, string expected)
1616
Assert.AreEqual(Normalize(expected), Normalize(actual));
1717
}
1818

19-
private static string Normalize(string text) => _normalize.Replace(text.Trim('\r', '\n') + Environment.NewLine, Environment.NewLine);
19+
static string Normalize(string text) => _normalize.Replace(text.Trim('\r', '\n') + Environment.NewLine, Environment.NewLine);
2020

21-
private static object[][] Cases =
21+
static object[][] Cases =
2222
{
2323
new object[] { new double[] { 1 }, null, " 1.00 ┼ " },
2424
new object[] { new double[] { 1, 1, 1, 1, 1 }, null, " 1.00 ┼──── " },
@@ -39,7 +39,7 @@ public void TestPlot(double[] series, Options opts, string expected)
3939
1.00 ┤╰─╯││ ╰
4040
0.00 ┤ ││
4141
-1.00 ┤ ││
42-
-2.00 ┤ ╰╯ "
42+
-2.00 ┤ ╰╯"
4343
},
4444
new object[]
4545
{
@@ -57,15 +57,15 @@ public void TestPlot(double[] series, Options opts, string expected)
5757
1.00 ┤╰─╯││ ││╰╯
5858
0.00 ┤ ││ ╰╯
5959
-1.00 ┤ ││
60-
-2.00 ┤ ╰╯ "
60+
-2.00 ┤ ╰╯"
6161
},
6262
new object[]
6363
{
6464
new[] { 0.2, 0.1, 0.2, 2, -0.9, 0.7, 0.91, 0.3, 0.7, 0.4, 0.5 }, null, @"
6565
2.00 ┤ ╭╮
6666
1.03 ┤ ││╭─╮╭╮╭
6767
0.07 ┼──╯││ ╰╯╰╯
68-
-0.90 ┤ ╰╯ "
68+
-0.90 ┤ ╰╯"
6969
},
7070
new object[]
7171
{
@@ -74,7 +74,7 @@ public void TestPlot(double[] series, Options opts, string expected)
7474
7.75 ┤ ╭─╯│╭╮
7575
4.50 ┼╮ ╭╮│ ╰╯│
7676
1.25 ┤╰─╯││ ╰
77-
-2.00 ┤ ╰╯ "
77+
-2.00 ┤ ╰╯"
7878
},
7979
new object[]
8080
{
@@ -87,7 +87,7 @@ public void TestPlot(double[] series, Options opts, string expected)
8787
0.44 ┼╮││ │ │╭╯
8888
0.34 ┤│││ │ ││
8989
0.24 ┤││╰─╯ ╰╯
90-
0.14 ┤╰╯ "
90+
0.14 ┤╰╯"
9191
},
9292
new object[]
9393
{
@@ -99,7 +99,7 @@ public void TestPlot(double[] series, Options opts, string expected)
9999
0.006 ┤│ │││
100100
0.005 ┤│ │││
101101
0.004 ┤╰╮╭╯││
102-
0.003 ┤ ╰╯ ╰╯ "
102+
0.003 ┤ ╰╯ ╰╯"
103103
},
104104
new object[]
105105
{
@@ -114,7 +114,7 @@ public void TestPlot(double[] series, Options opts, string expected)
114114
428 ┤╭╮╭╮╭╯││ │
115115
245 ┼╯╰╯││ ╰╯ ╰
116116
61 ┤ ││
117-
-122 ┤ ╰╯ "
117+
-122 ┤ ╰╯"
118118
},
119119
new object[]
120120
{
@@ -136,7 +136,7 @@ public void TestPlot(double[] series, Options opts, string expected)
136136
0.90 ┤ ╭╮ ││ ╭╯╰╮ ╭╮ ││ ╭╯╰╮ ╭╮ ││ ╭╯╰╮
137137
-0.40 ┼───╯╰──╯│╭─╯ ╰───────╯╰──╯│╭─╯ ╰───────╯╰──╯│╭─╯ ╰───
138138
-1.70 ┤ ││ ││ ││
139-
-3.00 ┤ ╰╯ ╰╯ ╰╯ "
139+
-3.00 ┤ ╰╯ ╰╯ ╰╯"
140140
},
141141
new object[]
142142
{
@@ -150,7 +150,7 @@ public void TestPlot(double[] series, Options opts, string expected)
150150
-6.00 ┤ ╰╮ │││ ││
151151
-7.00 ┤ ╰╮│││ ││
152152
-8.00 ┤ ╰╯││ ││
153-
-9.00 ┤ ╰╯ ╰╯ "
153+
-9.00 ┤ ╰╯ ╰╯"
154154
},
155155
new object[]
156156
{
@@ -186,7 +186,7 @@ public void TestPlot(double[] series, Options opts, string expected)
186186
39.47 ┤ ╰╮│ │╭╮
187187
38.46 ┤ ││ │││
188188
37.46 ┤ ╰╯ │││
189-
36.45 ┤ ╰╯╰ "
189+
36.45 ┤ ╰╯╰"
190190
},
191191
new object[] { new[] { 1, 1, double.NaN, 1, 1 }, null, @" 1.00 ┼─╴╶─ " },
192192
new object[] { new[] { double.NaN, 1 }, null, @" 1.00 ┤╶ " },
@@ -197,7 +197,7 @@ public void TestPlot(double[] series, Options opts, string expected)
197197
3.00 ┤ ╶─╯
198198
2.00 ┤
199199
1.00 ┤ ╭─╴
200-
0.00 ┼─╯ "
200+
0.00 ┼─╯"
201201
},
202202
new object[]
203203
{
@@ -211,7 +211,7 @@ public void TestPlot(double[] series, Options opts, string expected)
211211
0.40 ┤
212212
0.30 ┤ ╭╴
213213
0.20 ┤╭╯
214-
0.10 ┼╯ "
214+
0.10 ┼╯"
215215
}
216216
};
217217
}

AsciiChart.Sharp/AsciiChart.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,19 @@ public static string Plot(IEnumerable<double> series, Options options = null)
2727
var min2 = Math.Round(min * ratio, MidpointRounding.AwayFromZero);
2828
var max2 = Math.Round(max * ratio, MidpointRounding.AwayFromZero);
2929
var rows = Math.Abs(max2 - min2);
30-
30+
3131
var columnIndexOfFirstDataPoint = options.AxisLabelRightMargin + NumberOfNonDataColumns;
3232
var width = seriesList.Count + columnIndexOfFirstDataPoint;
3333

3434
var resultArray = CreateAndFill2dArray(rows, width, options.Fill.ToString());
3535

3636
var yAxisLabels = GetYAxisLabels(max, range, rows, options);
3737
ApplyYAxisLabels(resultArray, yAxisLabels, columnIndexOfFirstDataPoint);
38-
38+
3939
var rowIndex0 = Math.Round(seriesList[0] * ratio, MidpointRounding.AwayFromZero) - min2;
4040
if (!double.IsNaN(rowIndex0))
4141
{
42-
resultArray[(int) (rows - rowIndex0)][columnIndexOfFirstDataPoint - 1] = "┼";
42+
resultArray[(int)(rows - rowIndex0)][columnIndexOfFirstDataPoint - 1] = "┼";
4343
}
4444

4545
for (var x = 0; x < seriesList.Count - 1; x++)
@@ -52,25 +52,25 @@ public static string Plot(IEnumerable<double> series, Options options = null)
5252

5353
if (double.IsNaN(rowIndex0))
5454
{
55-
resultArray[(int) (rows - rowIndex1)][x + columnIndexOfFirstDataPoint] = "╶";
55+
resultArray[(int)(rows - rowIndex1)][x + columnIndexOfFirstDataPoint] = "╶";
5656
}
5757
else if (double.IsNaN(rowIndex1))
5858
{
59-
resultArray[(int) (rows - rowIndex0)][x + columnIndexOfFirstDataPoint] = "╴";
59+
resultArray[(int)(rows - rowIndex0)][x + columnIndexOfFirstDataPoint] = "╴";
6060
}
6161
else if (rowIndex0 == rowIndex1)
6262
{
63-
resultArray[(int) (rows - rowIndex0)][x + columnIndexOfFirstDataPoint] = "─";
63+
resultArray[(int)(rows - rowIndex0)][x + columnIndexOfFirstDataPoint] = "─";
6464
}
6565
else
6666
{
67-
resultArray[(int) (rows - rowIndex1)][x + columnIndexOfFirstDataPoint] = (rowIndex0 > rowIndex1) ? "╰" : "╭";
68-
resultArray[(int) (rows - rowIndex0)][x + columnIndexOfFirstDataPoint] = (rowIndex0 > rowIndex1) ? "╮" : "╯";
67+
resultArray[(int)(rows - rowIndex1)][x + columnIndexOfFirstDataPoint] = rowIndex0 > rowIndex1 ? "╰" : "╭";
68+
resultArray[(int)(rows - rowIndex0)][x + columnIndexOfFirstDataPoint] = rowIndex0 > rowIndex1 ? "╮" : "╯";
6969
var from = Math.Min(rowIndex0, rowIndex1);
7070
var to = Math.Max(rowIndex0, rowIndex1);
7171
for (var y = from + 1; y < to; y++)
7272
{
73-
resultArray[(int) (rows - y)][x + columnIndexOfFirstDataPoint] = "│";
73+
resultArray[(int)(rows - y)][x + columnIndexOfFirstDataPoint] = "│";
7474
}
7575
}
7676

@@ -82,7 +82,7 @@ public static string Plot(IEnumerable<double> series, Options options = null)
8282

8383
static string[][] CreateAndFill2dArray(double rows, int width, string fill)
8484
{
85-
var array = new string[((int)rows+1)][];
85+
var array = new string[(int)rows + 1][];
8686
for (var i = 0; i <= rows; i++)
8787
{
8888
array[i] = new string[width];
@@ -109,7 +109,7 @@ static IReadOnlyList<AxisLabel> GetYAxisLabels(double max, double range, double
109109
return labels;
110110
}
111111

112-
static IReadOnlyList<double> GetYAxisTicks(double max, double range, double rows)
112+
static IEnumerable<double> GetYAxisTicks(double max, double range, double rows)
113113
{
114114
var numberOfTicks = rows + 1;
115115
var yTicks = new List<double>();
@@ -121,7 +121,7 @@ static IReadOnlyList<double> GetYAxisTicks(double max, double range, double rows
121121
return yTicks;
122122
}
123123

124-
static void ApplyYAxisLabels(string[][] resultArray, IReadOnlyList<AxisLabel> yAxisLabels, int columnIndexOfFirstDataPoint)
124+
static void ApplyYAxisLabels(IReadOnlyList<string[]> resultArray, IReadOnlyList<AxisLabel> yAxisLabels, int columnIndexOfFirstDataPoint)
125125
{
126126
for (var i = 0; i < yAxisLabels.Count; i++)
127127
{
@@ -130,10 +130,10 @@ static void ApplyYAxisLabels(string[][] resultArray, IReadOnlyList<AxisLabel> yA
130130
}
131131
}
132132

133-
static string ToString(string[][] resultArray)
133+
static string ToString(IReadOnlyList<string[]> resultArray)
134134
{
135-
var rowStrings = resultArray.Select(row => String.Join("", row));
136-
return String.Join(Environment.NewLine, rowStrings);
135+
var rowStrings = resultArray.Select(row => string.Join("", row));
136+
return string.Join(Environment.NewLine, rowStrings);
137137
}
138138

139139
class AxisLabel
@@ -147,7 +147,7 @@ public AxisLabel(double value, string format)
147147
}
148148

149149
public double Value { get; }
150-
public int LeftPad { get; set; } = 0;
150+
public int LeftPad { get; set; }
151151
public string Label => Value.ToString(_format).PadLeft(LeftPad);
152152
}
153153
}

AsciiChart.Sharp/Options.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ public class Options
77
int _axisLabelLeftMargin = 1;
88
int _axisLabelRightMargin = 1;
99

10-
1110
/// <summary>
1211
/// The margin between the axis label and the left of the output.
1312
/// </summary>
@@ -18,7 +17,7 @@ public int AxisLabelLeftMargin
1817
{
1918
if (value < 0)
2019
{
21-
throw new ArgumentOutOfRangeException("Margin must be >= 0");
20+
throw new ArgumentOutOfRangeException(nameof(value), "Margin must be >= 0");
2221
}
2322
_axisLabelLeftMargin = value;
2423
}
@@ -34,12 +33,12 @@ public int AxisLabelRightMargin
3433
{
3534
if (value < 0)
3635
{
37-
throw new ArgumentOutOfRangeException("Margin must be >= 0");
36+
throw new ArgumentOutOfRangeException(nameof(value), "Margin must be >= 0");
3837
}
3938
_axisLabelRightMargin = value;
4039
}
4140
}
42-
41+
4342
/// <summary>
4443
/// Roughly the number of lines to scale the output to.
4544
/// </summary>

0 commit comments

Comments
 (0)