public void NumericCodeWithLengthOf2ShouldNotGoBeyond99() { var stopWatch = new System.Diagnostics.Stopwatch(); stopWatch.Start(); try { var codeList = new List <string>(); AttendanceCode code = null; for (int i = 0; i < 101; i++) { code = AttendanceCodeService.GetNew(0, 0, 2, false); codeList.Add(code.Code); } // should not be longer than 2 characters // This is a known bug in v7.4 and earlier, and possibly fixed via PR #3071 Assert.That.IsTrue(codeList.Last().Length == 2, "last code was " + codeList.Last().Length + " characters long."); } catch (TimeoutException) { // An exception in this case is considered better than hanging (since there is // no actual solution). Assert.That.IsTrue(true); } finally { stopWatch.Stop(); System.Diagnostics.Trace.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(Console.Out)); System.Diagnostics.Trace.WriteLine(string.Format("Test NumericCodeWithLengthOf2ShouldNotGoBeyond99 took {0} ms.", stopWatch.ElapsedMilliseconds)); } }
public void AlphaNumericWithNumericCodesShouldSkipBadCodes() { int attemptCombination = 0; try { var codeList = new List <string>(); AttendanceCode code = null; for (int i = 0; i < 600; i++) { attemptCombination = i; code = AttendanceCodeService.GetNew(2, 0, 3, true); codeList.Add(code.Code); } var matches = codeList.Where(c => AttendanceCodeService.noGood.Any(ng => c.Contains(ng))); bool hasMatchIsBad = matches.Any(); Assert.IsFalse(hasMatchIsBad, "bad codes were: " + string.Join(", ", matches)); } catch (TimeoutException) { // If an infinite loop was detected, but we tried at least 600 codes then // we'll consider this a pass. Assert.IsTrue(attemptCombination >= 600); } }
public void TwoAlphaWithFourRandomNumericCodesShouldSkipBadCodes() { var stopWatch = new System.Diagnostics.Stopwatch(); stopWatch.Start(); int attemptCombination = 0; var codeList = new List <string>(); AttendanceCode code = null; for (int i = 0; i < 2500; i++) { attemptCombination = i; code = AttendanceCodeService.GetNew(0, 2, 4, true); codeList.Add(code.Code); } // TODO: Once the combination of codes issue is addressed, this next line should be uncommented // and replace the one below it: //var matches = codeList.Where( c => AttendanceCodeService.noGood.Any( ng => c.Contains( ng ) ) ); var matches = codeList.Select(x => x).Intersect(AttendanceCodeService.noGood); bool hasMatchIsBad = matches.Any(); Assert.That.IsFalse(hasMatchIsBad, "bad codes were: " + string.Join(", ", matches)); stopWatch.Stop(); System.Diagnostics.Trace.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(Console.Out)); System.Diagnostics.Trace.WriteLine(string.Format("Test AlphaOnlyWithNumericOnlyCodesShouldSkipBadCodes took {0} ms.", stopWatch.ElapsedMilliseconds)); }
public void AlphaOnlyCodesShouldNotRepeat() { var stopWatch = new System.Diagnostics.Stopwatch(); stopWatch.Start(); var codeList = new List <string>(); AttendanceCode code = null; // 4847 (17*17*17 minus ~50 bad codes) possible combinations of 17 letters for (int i = 0; i < 4860; i++) { //System.Diagnostics.Debug.WriteIf( i > 4700, "code number " + i + " took... " ); code = AttendanceCodeService.GetNew(0, 3, 0, false); codeList.Add(code.Code); //System.Diagnostics.Debug.WriteLineIf( i > 4700, "" ); } var duplicates = codeList.GroupBy(x => x) .Where(group => group.Count() > 1) .Select(group => group.Key); Assert.That.IsTrue(duplicates.Count() == 0); stopWatch.Stop(); System.Diagnostics.Trace.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(Console.Out)); System.Diagnostics.Trace.WriteLine(string.Format("Test AlphaOnlyCodesShouldNotRepeat took {0} ms.", stopWatch.ElapsedMilliseconds)); }
public void RequestingMoreCodesThanPossibleShouldThrowException() { var codeList = new List <string>(); AttendanceCode code = null; // Generate 99 codes (the maximum number of valid codes). for (int i = 0; i < 100; i++) { code = AttendanceCodeService.GetNew(0, 0, 2, true); codeList.Add(code.Code); } // Now try to generate one more... which should NOT hang but instead, may // throw one of two exceptions. try { code = AttendanceCodeService.GetNew(0, 0, 2, true); } catch (InvalidOperationException) { Assert.IsTrue(true); } catch (TimeoutException) { // An exception in this case is considered better than hanging (since there is // no actual solution). Assert.IsTrue(true); } }
public void AlphaNumericWithNumericCodesShouldSkipBadCodes() { Cleanup(); int attemptCombination = 0; try { var codeList = new List <string>(); AttendanceCode code = null; for (int i = 0; i < 676; i++) { attemptCombination = i; code = AttendanceCodeService.GetNew(2, 0, 2, true); codeList.Add(code.Code); } bool hasMatchIsBad = codeList.Where(c => noGood.Any(ng => c.Contains(ng))).Any(); Assert.False(hasMatchIsBad); } catch (TimeoutException) { // If an infinite loop was detected, but we tried at least 616 codes then // we'll consider this a pass. Assert.True(attemptCombination >= 616); } }
public void NumericCodeWithLengthOf2ShouldNotGoBeyond99() { Cleanup(); try { var codeList = new List <string>(); AttendanceCode code = null; for (int i = 0; i < 101; i++) { code = AttendanceCodeService.GetNew(0, 0, 2, false); codeList.Add(code.Code); } // should not be longer than 4 characters // This is a known bug in v7.4 and earlier, and possibly fixed via PR #3071 Assert.True(codeList.Last().Length == 4); } catch (TimeoutException) { // An exception in this case is considered better than hanging (since there is // no actual solution). Assert.True(true); } }
public void RandomNumericCodesShouldNotRepeat() { var stopWatch = new System.Diagnostics.Stopwatch(); stopWatch.Start(); var codeList = new List <string>(); AttendanceCode code = null; for (int i = 0; i < 998; i++) { code = AttendanceCodeService.GetNew(0, 0, 3, true); codeList.Add(code.Code); } var duplicates = codeList.GroupBy(x => x) .Where(group => group.Count() > 1) .Select(group => group.Key); Assert.That.IsTrue(duplicates.Count() == 0, "repeated codes: " + string.Join(", ", duplicates)); stopWatch.Stop(); System.Diagnostics.Trace.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(Console.Out)); System.Diagnostics.Trace.WriteLine(string.Format("Test RandomNumericCodesShouldNotRepeat took {0} ms.", stopWatch.ElapsedMilliseconds)); }
public void AlphaNumericWith1NumericCodeShouldGenerateAtLeast5100Codes() { int attemptCombination = 0; var stopWatch = new System.Diagnostics.Stopwatch(); var stopWatchSingle = new System.Diagnostics.Stopwatch(); stopWatch.Start(); stopWatchSingle.Start(); var outputDebug = false; try { var codeList = new List <string>(); AttendanceCode code = null; for (int i = 1; i < 5100; i++) { attemptCombination = i; if (i > 4000 && i % 100 == 0) { outputDebug = true; stopWatchSingle.Restart(); System.Diagnostics.Debug.Write("code number " + i + " took... "); } code = AttendanceCodeService.GetNew(2, 0, 1, true); if (outputDebug) { System.Diagnostics.Debug.WriteLine(stopWatchSingle.ElapsedMilliseconds + " ms"); outputDebug = false; } codeList.Add(code.Code); } var matches = codeList.Where(c => AttendanceCodeService.NoGood.Any(ng => c.Contains(ng))); bool hasMatchIsBad = matches.Any(); Assert.That.IsFalse(hasMatchIsBad, "bad codes were: " + string.Join(", ", matches)); var duplicates = codeList.GroupBy(x => x) .Where(group => group.Count() > 1) .Select(group => group.Key); Assert.That.True(duplicates.Count() == 0); } catch (TimeoutException) { // If an infinite loop was detected, but we tried at least 5100 codes then // we'll consider this a pass. Assert.That.IsTrue(attemptCombination >= 5100); } finally { stopWatch.Stop(); System.Diagnostics.Trace.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(Console.Out)); System.Diagnostics.Trace.WriteLine(string.Format("Test AlphaNumericWith1NumericCodeShouldGenerateAtLeast5100Codes took {0} ms.", stopWatch.ElapsedMilliseconds)); } }
public void CheckThreeChar002Code() { AttendanceCode code = null; for (int i = 0; i < 2; i++) { code = AttendanceCodeService.GetNew(0, 0, 3, false); } Assert.AreEqual("002", code.Code); }
public void CheckThreeCharNumericNonRandom002Code() { AttendanceCode code = null; for (int i = 0; i < 2; i++) { code = AttendanceCodeService.GetNew(0, 0, 3, false); } Assert.That.Equal("002", code.Code); }
public void Increment100SequentialNumericCodes() { AttendanceCode code = null; for (int i = 0; i < 100; i++) { code = AttendanceCodeService.GetNew(0, 0, 3, false); } Assert.That.Equal("100", code.Code); }
public void NumericCodesShouldNotContain911And666() { var codeList = new List <string>(); AttendanceCode code = null; for (int i = 0; i < 2000; i++) { code = AttendanceCodeService.GetNew(0, 0, 4, false); codeList.Add(code.Code); } Assert.IsFalse(codeList.Any(s => s.Contains("911"))); Assert.IsFalse(codeList.Any(s => s.Contains("666"))); }
public void NumericCodesShouldSkip911And666() { var codeList = new List <string>(); AttendanceCode code = null; for (int i = 0; i < 2000; i++) { code = AttendanceCodeService.GetNew(0, 0, 4, false); codeList.Add(code.Code); } Assert.That.DoesNotContain(codeList, "911"); Assert.That.DoesNotContain(codeList, "666"); }
public void ThreeCharAlphaWithFourCharNumericCodesShouldSkipBadCodes() { var codeList = new List <string>(); AttendanceCode code = null; for (int i = 0; i < 6000; i++) { code = AttendanceCodeService.GetNew(0, 3, 4, true); codeList.Add(code.Code); } bool hasMatchIsBad = codeList.Where(c => AttendanceCodeService.NoGood.Any(ng => c.Contains(ng))).Any(); Assert.That.False(hasMatchIsBad); }
public void AlphaOnlyCodesShouldSkipBadCodes() { var codeList = new List <string>(); AttendanceCode code = null; for (int i = 0; i < 1000; i++) { code = AttendanceCodeService.GetNew(0, 3, 0, true); codeList.Add(code.Code); } bool hasMatchIsBad = codeList.Where(c => AttendanceCodeService.noGood.Any(ng => c.Contains(ng))).Any(); Assert.That.IsFalse(hasMatchIsBad); }
public void AlphaNumericCodesShouldNeverContain911And666() { Cleanup(); var codeList = new List <string>(); AttendanceCode code = null; for (int i = 0; i < 10000; i++) { code = AttendanceCodeService.GetNew(3, 0, 2, false); codeList.Add(code.Code); } Assert.False(codeList.Any(s => "911".Contains(s))); Assert.False(codeList.Any(s => "666".Contains(s))); }
public void AlphaOnlyWithNumericOnlyCodesShouldSkipBadCodes() { var codeList = new List <string>(); AttendanceCode code = null; for (int i = 0; i < 6000; i++) { code = AttendanceCodeService.GetNew(0, 1, 4, true); codeList.Add(code.Code); } var matches = codeList.Where(c => AttendanceCodeService.noGood.Any(ng => c.Contains(ng))); bool hasMatchIsBad = matches.Any(); Assert.IsFalse(hasMatchIsBad, "bad codes were: " + string.Join(", ", matches)); }
public void RandomNumericCodesShouldNotRepeat() { var codeList = new List <string>(); AttendanceCode code = null; for (int i = 0; i < 998; i++) { code = AttendanceCodeService.GetNew(0, 0, 3, true); codeList.Add(code.Code); } var duplicates = codeList.GroupBy(x => x) .Where(group => group.Count() > 1) .Select(group => group.Key); Assert.IsTrue(duplicates.Count() == 0, "repeated codes: " + string.Join(", ", duplicates)); }
public void AlphaNumericCodesShouldSkipBadCodes() { Cleanup(); var codeList = new List <string>(); AttendanceCode code = null; for (int i = 0; i < 6000; i++) { code = AttendanceCodeService.GetNew(3, 0, 0, false); codeList.Add(code.Code); } bool hasMatchIsBad = codeList.Where(c => noGood.Any(ng => c.Contains(ng))).Any(); Assert.False(hasMatchIsBad); }
public void NumericCodeWithLengthOf2ShouldNotGoBeyond99() { Cleanup(); var codeList = new List <string>(); AttendanceCode code = null; for (int i = 0; i < 101; i++) { code = AttendanceCodeService.GetNew(0, 0, 2, false); codeList.Add(code.Code); } // should not be longer than 4 characters // This is a known bug in v7.4 and earlier, and possibly fixed via PR #3071 Assert.True(codeList.Last().Length == 4); }
public void RandomNumericCodesShouldNotRepeat() { int maxThreeDigitCodes = 997; var codeList = new List <string>(); AttendanceCode code = null; for (int i = 1; i < maxThreeDigitCodes; i++) { code = AttendanceCodeService.GetNew(0, 0, 3, true); codeList.Add(code.Code); } var duplicates = codeList.GroupBy(x => x) .Where(group => group.Count() > 1) .Select(group => group.Key); Assert.That.True(duplicates.Count() == 0); }
public void AlphaNumericCodesShouldSkipBadCodes() { Cleanup(); var codeList = new List <string>(); AttendanceCode code = null; for (int i = 0; i < 6000; i++) { code = AttendanceCodeService.GetNew(3, 0, 0, false); codeList.Add(code.Code); } bool hasMatchIsBad = codeList.Select(x => x) .Intersect(noGood) .Any(); Assert.False(hasMatchIsBad); }
public void NumericCodesShouldNotRepeat() { Cleanup(); var codeList = new List <string>(); AttendanceCode code = null; for (int i = 0; i < 999; i++) { code = AttendanceCodeService.GetNew(0, 0, 3, false); codeList.Add(code.Code); } var duplicates = codeList.GroupBy(x => x) .Where(group => group.Count() > 1) .Select(group => group.Key); Assert.True(duplicates.Count() == 0); }
public void CheckThreeChar002Code() { var stopWatch = new System.Diagnostics.Stopwatch(); stopWatch.Start(); AttendanceCode code = null; for (int i = 0; i < 2; i++) { code = AttendanceCodeService.GetNew(0, 0, 3, false); } Assert.That.AreEqual("002", code.Code); stopWatch.Stop(); System.Diagnostics.Trace.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(Console.Out)); System.Diagnostics.Trace.WriteLine(string.Format("Test CheckThreeChar002Code took {0} ms.", stopWatch.ElapsedMilliseconds)); }
public void Increment100SequentialNumericCodes() { var stopWatch = new System.Diagnostics.Stopwatch(); stopWatch.Start(); AttendanceCode code = null; for (int i = 0; i < 100; i++) { code = AttendanceCodeService.GetNew(0, 0, 3, false); } Assert.That.AreEqual("100", code.Code); stopWatch.Stop(); System.Diagnostics.Trace.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(Console.Out)); System.Diagnostics.Trace.WriteLine(string.Format("Test Increment100SequentialNumericCodes took {0} ms.", stopWatch.ElapsedMilliseconds)); }
public void ThreeCharAlphaOnlyCodesShouldNotRepeat() { var codeList = new List <string>(); AttendanceCode code = null; // 4800 (17*17*17 minus ~80 badcodes) possible combinations of 17 letters for (int i = 0; i < 4800; i++) { //System.Diagnostics.Debug.WriteIf( i > 4700, "code number " + i + " took... " ); code = AttendanceCodeService.GetNew(0, 3, 0, false); codeList.Add(code.Code); //System.Diagnostics.Debug.WriteLineIf( i > 4700, "" ); } var duplicates = codeList.GroupBy(x => x) .Where(group => group.Count() > 1) .Select(group => group.Key); Assert.That.True(duplicates.Count() == 0); }
public void RequestingMoreCodesThanPossibleShouldThrowException() { var stopWatch = new System.Diagnostics.Stopwatch(); stopWatch.Start(); var codeList = new List <string>(); AttendanceCode code = null; // Generate 99 codes (the maximum number of valid codes). for (int i = 0; i < 100; i++) { code = AttendanceCodeService.GetNew(0, 0, 2, true); codeList.Add(code.Code); } // Now try to generate one more... which should NOT hang but instead, may // throw one of two exceptions. try { code = AttendanceCodeService.GetNew(0, 0, 2, true); } catch (InvalidOperationException) { Assert.That.IsTrue(true); } catch (TimeoutException) { // An exception in this case is considered better than hanging (since there is // no actual solution). Assert.That.IsTrue(true); } finally { stopWatch.Stop(); System.Diagnostics.Trace.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(Console.Out)); System.Diagnostics.Trace.WriteLine(string.Format("Test RequestingMoreCodesThanPossibleShouldThrowException took {0} ms.", stopWatch.ElapsedMilliseconds)); } }
public void NumericCodesShouldNotContain911And666() { var stopWatch = new System.Diagnostics.Stopwatch(); stopWatch.Start(); var codeList = new List <string>(); AttendanceCode code = null; for (int i = 0; i < 2000; i++) { code = AttendanceCodeService.GetNew(0, 0, 4, false); codeList.Add(code.Code); } Assert.That.IsFalse(codeList.Any(s => s.Contains("911"))); Assert.That.IsFalse(codeList.Any(s => s.Contains("666"))); stopWatch.Stop(); System.Diagnostics.Trace.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(Console.Out)); System.Diagnostics.Trace.WriteLine(string.Format("Test NumericCodesShouldNotContain911And666 took {0} ms.", stopWatch.ElapsedMilliseconds)); }
public void AlphaNumericCodesShouldSkipBadCodes() { var stopWatch = new System.Diagnostics.Stopwatch(); stopWatch.Start(); var codeList = new List <string>(); AttendanceCode code = null; for (int i = 0; i < 6000; i++) { code = AttendanceCodeService.GetNew(3, 0, 0, false); codeList.Add(code.Code); } bool hasMatchIsBad = codeList.Where(c => AttendanceCodeService.noGood.Any(ng => c.Contains(ng))).Any(); Assert.That.IsFalse(hasMatchIsBad); stopWatch.Stop(); System.Diagnostics.Trace.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(Console.Out)); System.Diagnostics.Trace.WriteLine(string.Format("Test AlphaNumericCodesShouldSkipBadCodes took {0} ms.", stopWatch.ElapsedMilliseconds)); }