[chronojump] Added testing file for compressing curves
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] Added testing file for compressing curves
- Date: Tue, 14 Apr 2015 11:32:25 +0000 (UTC)
commit da07b38c386183e0ae17bc5f73b78080de5fbffb
Author: Xavier de Blas <xaviblas gmail com>
Date: Tue Apr 14 13:31:58 2015 +0200
Added testing file for compressing curves
src/utilEncoder.cs | 4 ++
testing-stuff/compressCurve.cs | 74 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 78 insertions(+), 0 deletions(-)
---
diff --git a/src/utilEncoder.cs b/src/utilEncoder.cs
index 2645986..7cdae63 100644
--- a/src/utilEncoder.cs
+++ b/src/utilEncoder.cs
@@ -745,6 +745,10 @@ public class UtilEncoder
* valuesForNewLine is 25 means every 25 values there will be a newLine. 0 will mean no newlines
*/
+ /*
+ * valuesForNewLine means how many values want in a line. If it's >= []curve, then there will be only
one line
+ * there's a test of this function at testing-stuff/compressCurve.cs
+ */
public static string CompressData(double [] curve, int valuesForNewLine)
{
string compressed = "";
diff --git a/testing-stuff/compressCurve.cs b/testing-stuff/compressCurve.cs
new file mode 100644
index 0000000..0dc0312
--- /dev/null
+++ b/testing-stuff/compressCurve.cs
@@ -0,0 +1,74 @@
+//mcs compressCurve.cs
+
+using System;
+
+public class CompressCurve
+{
+ public static void Main() {
+ double [] curve = {
+ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0,
0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1,
1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1,
1, 1, 1, 1, 1,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1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1,
0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1,
1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1,
0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+ Console.WriteLine(CompressData(
+ curve,
+ curve.Length +1 //then all will come in one line
+ ));
+ }
+
+ //from utilEncoder.cs
+ //valuesForNewLine means how many values want in a line. If it's >= []curve, then there will be only
one line
+ public static string CompressData(double [] curve, int valuesForNewLine)
+ {
+ string compressed = "";
+
+ bool start = true;
+ int digit = -10000;
+ int digitPre = -10000; //just an impossible mark
+ int rep = 0;
+ int countNewLine = 0;
+
+ /*
+ LogB.Information("Compressing curve");
+ string debugStr = "";
+ for(int i=0; i < curve.Length; i++) {
+ debugStr += curve[i].ToString();
+ }
+ LogB.Debug(debugStr);
+ */
+
+ for(int i=0; i < curve.Length; i++)
+ {
+ digit = Convert.ToInt32(curve[i]);
+ if(start) {
+ rep ++;
+ start = false;
+ countNewLine ++;
+ } else if(digit == digitPre)
+ rep ++;
+ else {
+ if(rep == 1)
+ compressed += digitPre.ToString() + " ";
+ else {
+ compressed += digitPre.ToString() + "*" + rep.ToString() + " ";
+ rep = 1;
+ }
+ countNewLine ++;
+ }
+
+ if(valuesForNewLine > 0 && countNewLine >= valuesForNewLine) {
+ compressed += "\n";
+ countNewLine = 0;
+ }
+
+ digitPre = digit;
+ }
+
+ if(rep == 0)
+ compressed += "";
+ else if(rep == 1)
+ compressed += digit.ToString();
+ else
+ compressed += digit.ToString() + "*" + rep.ToString();
+
+ return compressed;
+ }
+}
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]