public void DoubleCountOnTwoTuple()
 {
     var sut = new Tuple<double, double>(1, 2);
       int expected = sut.AsEnumerable().Cast<double>().Count();
       int actual = sut.Count();
       Assert.AreEqual(expected, actual);
 }
Example #2
0
 public void LongCountOnTwoTuple()
 {
     var sut = new Tuple<long, long>(1, 2);
       int expected = sut.AsEnumerable().Cast<long>().Count();
       int actual = sut.Count();
       Assert.AreEqual(expected, actual);
 }
Example #3
0
 public static string AsString(Tuple<string, object>[] keyValues)
 {
     return keyValues.Count() == 1
         ? keyValues.First().Item2 as string
         : keyValues.Select(k => string.Format("{0}='{1}'", k.Item1, k.Item2))
             .Aggregate((c, n) => c + "," + n);
 }
 public void DecimalCountOnThreeTuple()
 {
     var sut = new Tuple<decimal, decimal, decimal>(1, 2, 3);
       int expected = sut.AsEnumerable().Cast<decimal>().Count();
       int actual = sut.Count();
       Assert.AreEqual(expected, actual);
 }
Example #5
0
 public void ShortCountOnTwoTuple()
 {
     var sut = new Tuple<short, short>(1, 2);
       int expected = sut.AsEnumerable().Cast<short>().Count();
       int actual = sut.Count();
       Assert.AreEqual(expected, actual);
 }
Example #6
0
 public TableRenderer(string title, Tuple<string, int>[] headers)
 {
     _title = title;
     _headers = headers;
     _totalWidth = _headers.Sum(h => h.Item2) + (_headers.Count() - 1) * 3;
     _rowTemplate = "| " + String.Join(" | ", _headers.Select((h, i) => "{" + i + ",-" + h.Item2 + "}").ToArray()) + " |";
 }
Example #7
0
 public void CountOnTwoTuple()
 {
     const int expected = 2;
       var t = new Tuple<int, int>(-1, -2);
       int actual = t.Count();
       Assert.AreEqual(expected, actual);
 }
 public void IntegerCountOnTwoTuple()
 {
     var sut = new Tuple<int, int>(1, 2);
       int expected = sut.AsEnumerable().Cast<int>().Count();
       int actual = sut.Count();
       Assert.AreEqual(expected, actual);
 }
Example #9
0
 public void CountOnSixTuple()
 {
     const int expected = 6;
       var t = new Tuple<int, int, int, int, int, int>(-1, -2, -3, -4, -5, -6);
       int actual = t.Count();
       Assert.AreEqual(expected, actual);
 }
Example #10
0
 public void CountOnOneTuple()
 {
     const int expected = 1;
       var t = new Tuple<int>(-1);
       int actual = t.Count();
       Assert.AreEqual(expected, actual);
 }
Example #11
0
 public void CountOnFourTuple()
 {
     const int expected = 4;
       var t = new Tuple<int, int, int, int>(-1, -2, -3, -4);
       int actual = t.Count();
       Assert.AreEqual(expected, actual);
 }
        internal static void VerifyResults(Tuple<string, string>[] expectedResults, IEnumerable<DbValidationError> actualResults)
        {
            Assert.Equal(expectedResults.Count(), actualResults.Count());

            foreach (var validationError in actualResults)
            {
                Assert.True(
                    expectedResults.SingleOrDefault(
                        r => r.Item1 == validationError.PropertyName && r.Item2 == validationError.ErrorMessage) != null,
                    String.Format(
                        "Unexpected error message '{0}' for property '{1}' not found", validationError.ErrorMessage,
                        validationError.PropertyName));
            }
        }
        private Tuple[] MergeAndCount(Tuple[] tuples, int[] ans, int start, int end)
        {
            if (start >= end)
            {
                return new Tuple[] { tuples[start] };
            }

            Tuple[] subTuple = new Tuple[end - start + 1];

            int m = start + (end - start) / 2;

            Tuple[] lefTuples = MergeAndCount(tuples, ans, start, m);
            Tuple[] rightTuples = MergeAndCount(tuples, ans, m + 1, end);

            int l = 0, r = 0;
            for (int i = 0; i <= end - start; i++)
            {
                if (r >= rightTuples.Count())
                {
                    subTuple[i] = lefTuples[l++];
                    continue;
                }

                if (l >= lefTuples.Count())
                {
                    subTuple[i] = rightTuples[r++];
                    continue;
                }

                if (r < rightTuples.Count() && lefTuples[l].Value > rightTuples[r].Value)
                {
                    subTuple[i] = rightTuples[r];
                    int t = l;
                    while (t < lefTuples.Count())
                    {
                        ans[lefTuples[t++].Index]++;
                    }
                    r++;
                }
                else if (l < lefTuples.Count())
                {
                    subTuple[i] = lefTuples[l++];
                }
            }

            for (int i = 0; i < subTuple.Count(); i++)
            {
                tuples[start++] = subTuple[i];
            }

            return subTuple;
        }