120 lines
4.5 KiB
C#
120 lines
4.5 KiB
C#
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
using TrackTrends;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.IO;
|
|
using System.Drawing;
|
|
|
|
namespace TrackTrends.Tests
|
|
{
|
|
[TestClass()]
|
|
public class OcrImageTests
|
|
{
|
|
[TestMethod()]
|
|
public void LapTimeOCR_Test()
|
|
{
|
|
string directory = @"./../../TestImages/LapTimes/";
|
|
foreach (string file in Directory.GetFiles(directory))
|
|
{
|
|
Bitmap image = (Bitmap)Image.FromFile(file);
|
|
DriverLapTimeWindow lapTimeWindow = new DriverLapTimeWindow(image,new Rectangle(0,0,image.Width,image.Height),true);
|
|
string[] paths = file.Split('/');
|
|
string fileName = paths[paths.Length - 1];
|
|
fileName = fileName.Replace(".png","");
|
|
|
|
int timeMS = (int)lapTimeWindow.DecodePng();
|
|
string time = Reader.ConvertMsToTime(timeMS);
|
|
|
|
string[] checkDigits = fileName.Split('_');
|
|
string[] digitsToCheck = time.Split(':');
|
|
|
|
//The ConvertMSToTime will always return three chars so we need to make the checkDigits be also three chars
|
|
while (checkDigits.Length != 3)
|
|
checkDigits = new[] { "0" }.Concat(checkDigits).ToArray();
|
|
|
|
for (int i = 0; i < checkDigits.Length; i++)
|
|
{
|
|
Assert.AreEqual(checkDigits[i], digitsToCheck[i]);
|
|
}
|
|
}
|
|
}
|
|
[TestMethod()]
|
|
public void PositionOCR_Test()
|
|
{
|
|
Assert.Fail();
|
|
}
|
|
[TestMethod()]
|
|
public void GapToLeaderOCR_Test()
|
|
{
|
|
string directory = @"./../../TestImages/Gaps/";
|
|
foreach (string file in Directory.GetFiles(directory))
|
|
{
|
|
Bitmap image = (Bitmap)Image.FromFile(file);
|
|
DriverGapToLeaderWindow gapsWindow = new DriverGapToLeaderWindow(image, new Rectangle(0, 0, image.Width, image.Height), true);
|
|
string[] paths = file.Split('/');
|
|
string fileName = paths[paths.Length - 1];
|
|
fileName = fileName.Replace(".png", "");
|
|
|
|
int timeMS = (int)gapsWindow.DecodePng();
|
|
string time = Reader.ConvertMsToTime(timeMS);
|
|
|
|
string[] checkDigits = fileName.Split('_');
|
|
string[] digitsToCheck = time.Split(':');
|
|
|
|
if (time == "0:00:000")
|
|
{
|
|
Assert.AreEqual(0, Convert.ToInt32(checkDigits[0]));
|
|
}
|
|
else
|
|
{
|
|
//The ConvertMSToTime will always return three chars so we need to make the checkDigits be also three chars
|
|
while(checkDigits.Length != 3)
|
|
checkDigits = new[] { "0" }.Concat(checkDigits).ToArray();
|
|
|
|
for (int i = 0; i < checkDigits.Length; i++)
|
|
{
|
|
//We need to convert to int first because sometimes we have "08" and "8" and in string its not the same but in int it is
|
|
Assert.AreEqual(Convert.ToInt32(checkDigits[i]), Convert.ToInt32(digitsToCheck[i]));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
[TestMethod()]
|
|
public void DRS_OCR_Test()
|
|
{
|
|
string directory = @"./../../TestImages/DRS/";
|
|
DirectoryInfo directoryInfo = new DirectoryInfo(directory);
|
|
if (Directory.Exists(directory))
|
|
{
|
|
Bitmap falseExemple = (Bitmap)Image.FromFile(directory + "False.png");
|
|
Bitmap trueExemple = (Bitmap)Image.FromFile(directory + "True.png");
|
|
|
|
DriverDrsWindow falseDRS = new DriverDrsWindow(falseExemple, new Rectangle(0, 0, falseExemple.Width, falseExemple.Height), true);
|
|
DriverDrsWindow trueDRS = new DriverDrsWindow(trueExemple, new Rectangle(0, 0, trueExemple.Width, trueExemple.Height), true);
|
|
|
|
bool falseResult = (bool)falseDRS.DecodePng();
|
|
bool trueResult = (bool)trueDRS.DecodePng();
|
|
|
|
Assert.IsFalse(falseResult);
|
|
Assert.IsTrue(trueResult);
|
|
}
|
|
else
|
|
{
|
|
Assert.Fail();
|
|
}
|
|
}
|
|
[TestMethod()]
|
|
public void DriverNameOCR_Test()
|
|
{
|
|
Assert.Fail();
|
|
}
|
|
[TestMethod()]
|
|
public void SectorOCR_Test()
|
|
{
|
|
Assert.Fail();
|
|
}
|
|
}
|
|
} |