×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: C#
Posted by: Alex Brah
Added: Apr 13, 2017 9:57 PM
Modified: Apr 13, 2017 10:38 PM
Views: 10
Tags: no tags
Unit test for "MostFrequentTriplet" method
  1.  
  2. public void TestMostFrequentTriplet()
  3. {
  4.     //arrange
  5.     var class1 = new Class1(); ;
  6.     var cancelSource = new CancellationTokenSource();
  7.     var token = cancelSource.Token; ;
  8.     var task1 = new Task<string>(() => { return class1.MostFrequentTriplet("ala,bala,lylkuk,kukkuklyl,lyl,lyl,kuk,rolrolrolrol,wfwf", new CancellationToken()); });
  9.     var task2 = new Task<string>(() => { return class1.MostFrequentTriplet("", new CancellationToken()); });
  10.     var task3 = new Task<string>(() => { return class1.MostFrequentTriplet("", token); });
  11.  
  12.     //act
  13.     cancelSource.Cancel();
  14.     task1.Start();
  15.     task2.Start();
  16.     task3.Start();
  17.  
  18.     //assert
  19.     Assert.AreEqual("lyl,kuk,rol\t4", class1.MostFrequentTriplet("ala,bala,lylkuk,kukkuklyl,lyl,lyl,kuk,rolrolrolrol,wfwf", new CancellationToken()), "should define most frequent triplets (1)");
  20.     Assert.AreEqual("qqq\t3", class1.MostFrequentTriplet("qqqqqqqqqq", new CancellationToken()), "should define most frequent triplets (2)");
  21.     Assert.AreEqual("AAA,DAD\t2", class1.MostFrequentTriplet("AAA,DAD,DADA,AAA,aaa", new CancellationToken()), "should define most frequent triplets (3)");
  22.     Assert.AreEqual("Canceled!", class1.MostFrequentTriplet("ala", token), "should return 'Canceled! (1)");
  23.     Assert.AreEqual("Canceled!", class1.MostFrequentTriplet(" 1", token), "should return 'Canceled! (2)");
  24.     Assert.AreEqual("Wrong 'str' argument, 'str' should contain only letters and commas", class1.MostFrequentTriplet("123", new CancellationToken()), "should return exception's message(1)");
  25.     Assert.AreEqual("Wrong 'str' argument, 'str' should contain only letters and commas", class1.MostFrequentTriplet("*/- =+()&^%$#@!?><|~", new CancellationToken()), "should return exception's message(2)");
  26.     Assert.AreEqual("lyl,kuk,rol\t4", task1.Result, "should return correct results of task1");
  27.     Assert.AreEqual("Wrong 'str' argument, 'str' should contain only letters and commas", task2.Result, "should return exception's message of task2");
  28.     Assert.AreEqual("Canceled!", task3.Result, "should return 'Canceled!' from task3");
  29. }
  30.  
  31. Имя теста:      TestMostFrequentTriplet
  32. Полное имя теста: UnitTestProject1.UnitTest1.TestMostFrequentTriplet
  33. Источник теста:    d:\users\user\documents\visual studio 2017\Projects\ConsoleApp1\UnitTestProject1\UnitTest1.cs : строка 16
  34. Выходные данные теста:       Пройден
  35. Продолжительность теста:  0:00:00,0141578
  36.