public void ReadTwoSetKits() { _fuspecTestCases = TestHelper.GenerateFuspecTestCases( @"|******************** | TEST Name | TAGS tag1 |************************ | in a:real b:int | out x:real |------------------------ x = a-b |--------------------- | set a:1, b:2, c:4.4 | set a:2, b:3, c:3.0 "); Assert.Multiple(() => { TestHelper.AssertForCorrectTestCase(_fuspecTestCases); Assert.AreEqual(2, _fuspecTestCases.TestCases.FirstOrDefault().SetChecks.Length); var setOrChecksKit1 = _fuspecTestCases.TestCases.FirstOrDefault().SetChecks[0]; var setOrChecksKit2 = _fuspecTestCases.TestCases.FirstOrDefault().SetChecks[1]; Assert.IsTrue(setOrChecksKit1 is SetData, "First kit isn't SET type"); Assert.IsTrue(setOrChecksKit2 is SetData, "Second kit isn't SET type"); }); }
internal static void AssertForCorrectTestCase(FuspecTestCases fuspecTestCases) { Assert.IsNotNull(fuspecTestCases, "FuspecTestCases = null. It shouldn't be null!"); Assert.IsNotNull(fuspecTestCases.TestCases, "FuspecTestCases.TestCases = null. It shouldn't be null!"); Assert.IsNotNull(fuspecTestCases.Errors, "FuspecTestCases.Errors = null. It shouldn't be null!"); Assert.AreEqual(0, fuspecTestCases.Errors.Length, "Parser wrote nonexistent error. Expected 0 errors!"); Assert.AreEqual(true, fuspecTestCases.TestCases.Any(), "Parser didn't write testcase. Expected some sucsessful tests!"); }
internal static void StandardAssertForNotCorrectTestCase(FuspecTestCases fuspecTestCases) { Assert.IsNotNull(fuspecTestCases, "FuspecTestCases = null. It shouldn't be null!"); Assert.IsNotNull(fuspecTestCases.TestCases, "FuspecTestCases.TestCases = null. It shouldn't be null!"); Assert.IsNotNull(fuspecTestCases.Errors, "FuspecTestCases.Errors = null. It shouldn't be null!"); Assert.IsTrue(fuspecTestCases.Errors.Any(), "Parser didn't write error. Expected some errors!"); Assert.AreEqual(0, fuspecTestCases.TestCases.Length, "Wrong number of Tests.Expected 0 TestCase!"); }
private void GenerateFuspecTestCases(string str) { List <string> listOfString = new List <string>(); using (TextReader tr = new StringReader(str)) { string line; while ((line = tr.ReadLine()) != null) { listOfString.Add(line); } } var inputText = InputText.Read(new StreamReader(GenerateStreamFromString(str))); _fuspecTestCases = new TestCasesReader().Read(inputText); }
public void WrongTestCaseWithoutKeWordTAGS_ReturnError_EndingHeadMissed() { _fuspecTestCases = TestHelper.GenerateFuspecTestCases( @"|************************ | TEST Complex example | Tag1, Tag2 |************************ x = round(a + b + c)"); Assert.Multiple(() => { TestHelper.StandardAssertForNotCorrectTestCase(_fuspecTestCases); Assert.AreEqual(FuspecErrorType.EndingHeadMissed, _fuspecTestCases.Errors[0].ErrorType, "Fuspec didn't write EndingHeadMissed Error"); }); }
public void CorrectTestCaseWithComma_ReturnNoTags() { _fuspecTestCases = TestHelper.GenerateFuspecTestCases( @"|************************ | TEST Complex example | TAGS , , |************************ x = round(a + b + c)"); Assert.Multiple(() => { TestHelper.AssertForCorrectTestCase(_fuspecTestCases); Assert.AreEqual(1, _fuspecTestCases.TestCases.Length, "Wrong number of Tests. Expected 1 TestCase!"); Assert.AreEqual(0, _fuspecTestCases.TestCases.FirstOrDefault().Tags.Length, "Wrong number of tags. Expected 0"); }); }
[Test]//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! public void ParamsReading_ParamsAndTwoCommas_returnErrorParamMissed() { _fuspecTestCases = TestHelper.GenerateFuspecTestCases( @"|******************** | TEST Name | TAGS tag1 |************************ | out a:real,, |----------------------------- x = round(a - b - c) "); Assert.Multiple(() => { TestHelper.StandardAssertForNotCorrectTestCase(_fuspecTestCases); }); }
public void ParamsReading_NoSpaceAfterKeyWord_returnErrorParamMissed() { _fuspecTestCases = TestHelper.GenerateFuspecTestCases( @"|******************** | TEST Name | TAGS tag1 |************************ | outa:real |-------------------------------- x = round(a - b - c) "); Assert.Multiple(() => { TestHelper.StandardAssertForNotCorrectTestCase(_fuspecTestCases); Assert.AreEqual(FuspecErrorType.ParamOutMissed, _fuspecTestCases.Errors.FirstOrDefault().ErrorType); }); }
public void ParamsReading_TwoCommasInsteadParams_returnError() { _fuspecTestCases = TestHelper.GenerateFuspecTestCases( @"|******************** | TEST Name | TAGS tag1 |************************ | out ,, |----------------------- x = round(a - b - c) "); Assert.Multiple(() => { TestHelper.StandardAssertForNotCorrectTestCase(_fuspecTestCases); Assert.AreEqual(FuspecErrorType.NFunMessage_ICantParseParamTypeString, _fuspecTestCases.Errors.FirstOrDefault().ErrorType); }); }
public void NoSetCheckBlock_ReadOneTest() { _fuspecTestCases = TestHelper.GenerateFuspecTestCases( @"|******************** | TEST Name | TAGS tag1 |************************ | in a:real b:int | out x:real |------------------------ x = a-b |--------------------- "); Assert.Multiple(() => { TestHelper.AssertForCorrectTestCase(_fuspecTestCases); Assert.AreEqual(1, _fuspecTestCases.TestCases.Length); }); }
public void CorrectTestCaseWithEmptyTag_ReturnNoTags() { _fuspecTestCases = TestHelper.GenerateFuspecTestCases( @"|************************ | TEST Complex example | TAGS |************************ x = round(a + b + c) x = round(a + b + c)"); Assert.Multiple(() => { TestHelper.AssertForCorrectTestCase(_fuspecTestCases); Assert.AreEqual(1, _fuspecTestCases.TestCases.Length, "Wrong number of Tests. Expected 1 TestCase!"); Assert.AreEqual("Complex example", _fuspecTestCases.TestCases.FirstOrDefault().Name, "Set wrong Name"); Assert.AreEqual(0, _fuspecTestCases.TestCases.FirstOrDefault().Tags.Length, "Set wrong Tags. Nonexistent tag was added"); }); }
public void ParamsReading_ReadJustParamsOut_returnParamsIn() { _fuspecTestCases = TestHelper.GenerateFuspecTestCases( @"|******************** | TEST Name | TAGS tag1 |************************ | out y:real[] |---------------- x = round(a - b - c) "); Assert.Multiple(() => { TestHelper.AssertForCorrectTestCase(_fuspecTestCases); Assert.AreEqual("y", _fuspecTestCases.TestCases.FirstOrDefault().OutputVarList[0].Name); Assert.AreEqual("Real[]", _fuspecTestCases.TestCases.FirstOrDefault().OutputVarList[0].Type.ToString()); }); }
public void CorrectTestCaseWithSpaceBarTag_ReturnTagWithoutSpaces() { _fuspecTestCases = TestHelper.GenerateFuspecTestCases( @"|************************ | TEST Complex example | TAGS Tag1 |************************ x = round(a + b + c)"); Assert.Multiple(() => { TestHelper.AssertForCorrectTestCase(_fuspecTestCases); Assert.AreEqual(1, _fuspecTestCases.TestCases.Length, "Wrong number of Tests. Expected 1 TestCase!"); Assert.AreEqual(1, _fuspecTestCases.TestCases.FirstOrDefault().Tags.Length, "Wrong number of tags. Expected 1"); Assert.AreEqual("Tag1", _fuspecTestCases.TestCases.FirstOrDefault().Tags[0], "Set wrong Tag. Expected Tag1"); }); }
public void ParamsReading_TwoParamsIn_returnTwoInParams() { _fuspecTestCases = TestHelper.GenerateFuspecTestCases( @"|******************** | TEST Name | TAGS tag1 |************************ | in a:real, b:real |--------------------------- x = round(a - b - c) "); Assert.Multiple(() => { TestHelper.AssertForCorrectTestCase(_fuspecTestCases); Assert.AreEqual("a", _fuspecTestCases.TestCases.FirstOrDefault().InputVarList[0].Name); Assert.AreEqual("Real", _fuspecTestCases.TestCases.FirstOrDefault().InputVarList[0].Type.ToString()); Assert.AreEqual("b", _fuspecTestCases.TestCases.FirstOrDefault().InputVarList[1].Name); Assert.AreEqual("Real", _fuspecTestCases.TestCases.FirstOrDefault().InputVarList[1].Type.ToString()); }); }
public void MissedSpaseAfterCheck_ReturnError() { _fuspecTestCases = TestHelper.GenerateFuspecTestCases( @"|******************** | TEST Name | TAGS tag1 |************************ | in a:real b:int | out x:real |------------------------ x = a-b |--------------------- | checka:5,b:4 "); Assert.Multiple(() => { TestHelper.StandardAssertForNotCorrectTestCase(_fuspecTestCases); Assert.AreEqual(FuspecErrorType.WrongSetCheckKit, _fuspecTestCases.Errors.FirstOrDefault().ErrorType); }); }
[Test]//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1 public void ParamsReading_TwoOutParamsWithSimilarValues_returnError() { _fuspecTestCases = TestHelper.GenerateFuspecTestCases( @"|******************** | TEST Name | TAGS tag1 |************************ | out a:real, a:int |----------------------------- x = round(a - b - c) "); // не организована проверка! Assert.Multiple(() => { TestHelper.StandardAssertForNotCorrectTestCase(_fuspecTestCases); Assert.AreEqual(FuspecErrorType.NFunMessage_ICantParseParamTypeString, _fuspecTestCases.Errors.FirstOrDefault().ErrorType); // Assert.AreEqual("a",_fuspecTestCases.TestCases.FirstOrDefault().ParamsOut[0].Value); // Assert.AreEqual("Real",_fuspecTestCases.TestCases.FirstOrDefault().ParamsOut[0].VarType.ToString()); // Assert.AreEqual("b",_fuspecTestCases.TestCases.FirstOrDefault().ParamsOut[1].Value); // Assert.AreEqual("Int32",_fuspecTestCases.TestCases.FirstOrDefault().ParamsOut[1].VarType.ToString()); }); }
public void ReadCheckValue() { _fuspecTestCases = TestHelper.GenerateFuspecTestCases( @"|******************** | TEST Name | TAGS tag1 |************************ | in a:real b:int | out x:real |------------------------ x = a-b |--------------------- | check a:1, b:2, c:4.4 "); Assert.Multiple(() => { TestHelper.AssertForCorrectTestCase(_fuspecTestCases); Assert.AreEqual(1, _fuspecTestCases.TestCases.FirstOrDefault().SetChecks.Length); var setOrChecksKit1 = _fuspecTestCases.TestCases.FirstOrDefault().SetChecks[0]; Assert.IsTrue(setOrChecksKit1 is CheckData, "First kit isn't Check type"); if (setOrChecksKit1 is CheckData CheckKit1) { Assert.AreEqual("a", CheckKit1.ValuesKit[0].Name, "Wrong Name of first data in the first kit"); Assert.AreEqual(VarType.Real, CheckKit1.ValuesKit[0].Type, "Wrong Type of first data in the first kit"); Assert.AreEqual(1, CheckKit1.ValuesKit[0].Value, "Wrong Value of first data in the first kit"); Assert.AreEqual("b", CheckKit1.ValuesKit[1].Name, "Wrong Name of second data in the first kit"); Assert.AreEqual(VarType.Real, CheckKit1.ValuesKit[1].Type, "Wrong Type of second data in the first kit"); Assert.AreEqual(2, CheckKit1.ValuesKit[1].Value, "Wrong Value of second data in the first kit"); Assert.AreEqual("c", CheckKit1.ValuesKit[2].Name, "Wrong Name of third data in the first kit"); Assert.AreEqual(VarType.Real, CheckKit1.ValuesKit[2].Type, "Wrong Type of third data in the first kit"); Assert.AreEqual(4.4, CheckKit1.ValuesKit[2].Value, "Wrong Value of third data in the first kit"); } }); }
public void ReadTwoFuspecCaseWithSetCheckKits_ReturnTwoFuspecCases() { _fuspecTestCases = TestHelper.GenerateFuspecTestCases( @"|******************** | TEST Name | TAGS tag1 |************************ | in a:real b:int | out x:real |------------------------ x = a-b |--------------------- | set a:5 ,b:4 | check h:5, y:4 | set a:5, b:4 | check h:5, y:4 |*************** | TEST Name | TAGS tag1 |************************ | in a:real b:int | out x:real |------------------------ x = a-b |--------------------- | set a:5, b:4 | check h:5, y:4 "); Assert.Multiple(() => { Assert.AreEqual(0, _fuspecTestCases.Errors.Length, "Parser wrote nonexistent error "); Assert.AreEqual(2, _fuspecTestCases.TestCases.Length); }); }
public void ParamsReading_ReadSimpleParamsWithEnterAfterParams_returnParams() { _fuspecTestCases = TestHelper.GenerateFuspecTestCases( @"|******************** | TEST Name | TAGS tag1 |************************ | in a:real | out y:real |------------------------ x = round(a - b - c) "); Assert.Multiple(() => { TestHelper.AssertForCorrectTestCase(_fuspecTestCases); Assert.AreEqual("\r\n x = round(a - b - c) ", _fuspecTestCases.TestCases.FirstOrDefault().Script); Assert.AreEqual("a", _fuspecTestCases.TestCases.FirstOrDefault().InputVarList[0].Name); Assert.AreEqual("Real", _fuspecTestCases.TestCases.FirstOrDefault().InputVarList[0].Type.ToString()); Assert.AreEqual("y", _fuspecTestCases.TestCases.FirstOrDefault().OutputVarList[0].Name); Assert.AreEqual("Real", _fuspecTestCases.TestCases.FirstOrDefault().OutputVarList[0].Type.ToString()); }); }
public void ReadWrongStringBeforeSetCheckKit_ReturnError() { _fuspecTestCases = TestHelper.GenerateFuspecTestCases( @"|******************** | TEST Name | TAGS tag1 |************************ | in a:real b:int | out x:real |------------------------ x = a-b |--------------------- | sdfsdfdf | set a:5, b:4 | check a:5 "); Assert.Multiple(() => { TestHelper.StandardAssertForNotCorrectTestCase(_fuspecTestCases); Assert.AreEqual(FuspecErrorType.ExpectedOpeningLine, _fuspecTestCases.Errors.FirstOrDefault().ErrorType); }); }