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));
            }
        }
Exemplo n.º 2
0
 public void CountOnTwoTuple()
 {
     const int expected = 2;
       var t = new Tuple<int, int>(-1, -2);
       int actual = t.Count();
       Assert.AreEqual(expected, actual);
 }
Exemplo n.º 3
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);
 }
Exemplo n.º 4
0
 public void CountOnOneTuple()
 {
     const int expected = 1;
       var t = new Tuple<int>(-1);
       int actual = t.Count();
       Assert.AreEqual(expected, actual);
 }
Exemplo n.º 5
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);
 }
Exemplo n.º 6
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);
 }
Exemplo n.º 7
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);
 }
Exemplo n.º 8
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()) + " |";
 }
Exemplo n.º 9
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);
 }
Exemplo n.º 10
0
 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);
 }
Exemplo n.º 11
0
 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);
 }
Exemplo n.º 12
0
 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);
 }
Exemplo n.º 13
0
    public static double Average <T1, T2>(this Tuple <T1, T2> value, Func <object, double> func)
    {
        Contract.Requires <ArgumentNullException>(value != null);
        Contract.Requires <ArgumentNullException>(func != null);
        double average = value.Sum(func) / value.Count();

        return(average);
    }
Exemplo n.º 14
0
        public void Tuple_Single_Count()
        {
            Tuple <int, string> tuple1 = new Tuple <int, string>(10, "Hello");
            Tuple <int, int, int, int, int, int> tuple2 = new Tuple <int, int, int, int, int, int>(1, 2, 3, 4, 5, 6);

            Assert.AreEqual(2, tuple1.Count());
            Assert.AreEqual(6, tuple2.Count());
        }
Exemplo n.º 15
0
        public void CountOnSevenTuple()
        {
            const int expected = 7;
            var       t        = new Tuple <int, int, int, int, int, int, int>(-1, -2, -3, -4, -5, -6, -7);
            int       actual   = t.Count();

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 16
0
        public void CountOnFiveTuple()
        {
            const int expected = 5;
            var       t        = new Tuple <int, int, int, int, int>(-1, -2, -3, -4, -5);
            int       actual   = t.Count();

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 17
0
        public void CountOnThreeTuple()
        {
            const int expected = 3;
            var       t        = new Tuple <int, int, int>(-1, -2, -3);
            int       actual   = t.Count();

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 18
0
        public void CountOnOneTuple()
        {
            const int expected = 1;
            var       t        = new Tuple <int>(-1);
            int       actual   = t.Count();

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 19
0
        public void LongCountOnSixTuple()
        {
            var sut      = new Tuple <long, long, long, long, long, long>(1, 2, 3, 4, 5, 6);
            int expected = sut.AsEnumerable().Cast <long>().Count();
            int actual   = sut.Count();

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 20
0
        public void IntegerCountOnSixTuple()
        {
            var sut      = new Tuple <int, int, int, int, int, int>(1, 2, 3, 4, 5, 6);
            int expected = sut.AsEnumerable().Cast <int>().Count();
            int actual   = sut.Count();

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 21
0
    public static double?Average <T1, T2, T3, T4>(this Tuple <T1, T2, T3, T4> value, Func <object, short?> func)
    {
        Contract.Requires <ArgumentNullException>(value != null);
        Contract.Requires <ArgumentNullException>(func != null);

        double?average = value.Sum(func) / (double?)value.Count();

        return(average);
    }
Exemplo n.º 22
0
    public static decimal?Average <T1, T2, T3, T4, T5>(this Tuple <T1, T2, T3, T4, T5> value, Func <object, decimal?> func)
    {
        Contract.Requires <ArgumentNullException>(value != null);
        Contract.Requires <ArgumentNullException>(func != null);

        decimal?average = value.Sum(func) / value.Count();

        return(average);
    }
Exemplo n.º 23
0
    public static double Average <T1, T2, T3, T4, T5, T6, T7>(this Tuple <T1, T2, T3, T4, T5, T6, T7> value,
                                                              Func <object, long> func)
    {
        Contract.Requires <ArgumentNullException>(value != null);
        Contract.Requires <ArgumentNullException>(func != null);

        double average = value.Sum(func) / (double)value.Count();

        return(average);
    }
Exemplo n.º 24
0
        public void Tuple_Long_Count()
        {
            Tuple <int, string, int, string, int, string, int, Tuple <int, string, int, string, int, string> > tuple1 = new Tuple <int, string, int, string, int, string, int, Tuple <int, string, int, string, int, string> >(10, "Hello", 11, "World", 12, "Test", 13,
                                                                                                                                                                                                                               new Tuple <int, string, int, string, int, string>(14, "Happy", 15, "Fiction", 16, "Last"));
            Tuple <int, int, int, int, int, int, int, Tuple <int, int, int, int, int, int, int, Tuple <int, int, int, int, int, int, int, Tuple <int, int, int, int, int, int, int, Tuple <int, int, int, int, int, int, int> > > > > tuple2 = new Tuple <int, int, int, int, int, int, int, Tuple <int, int, int, int, int, int, int, Tuple <int, int, int, int, int, int, int, Tuple <int, int, int, int, int, int, int, Tuple <int, int, int, int, int, int, int> > > > >(1, 2, 3, 4, 5, 6, 7,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                             new Tuple <int, int, int, int, int, int, int, Tuple <int, int, int, int, int, int, int, Tuple <int, int, int, int, int, int, int, Tuple <int, int, int, int, int, int, int> > > >(8, 9, 10, 11, 12, 13, 14,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               new Tuple <int, int, int, int, int, int, int, Tuple <int, int, int, int, int, int, int, Tuple <int, int, int, int, int, int, int> > >(15, 16, 17, 18, 19, 20, 21,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     new Tuple <int, int, int, int, int, int, int, Tuple <int, int, int, int, int, int, int> >(22, 23, 24, 25, 26, 27, 28,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               new Tuple <int, int, int, int, int, int, int>(29, 30, 31, 32, 33, 34, 35)))));

            Assert.AreEqual(13, tuple1.Count());
            Assert.AreEqual(35, tuple2.Count());
        }
Exemplo n.º 25
0
    public static double?Max <T1, T2, T3, T4, T5>(this Tuple <T1, T2, T3, T4, T5> value, Func <object, double?> func)
    {
        Contract.Requires <ArgumentNullException>(value != null);
        Contract.Requires <ArgumentNullException>(func != null);

        double?max = double.MinValue;
        int    i   = value.Count();

        while (0 < i)
        {
            i--;
            object v      = value.Item(i);
            double?fValue = func(v);
            if (fValue.HasValue)
            {
                max = Math.Max(max.Value, fValue.Value);
            }
        }
        return(max);
    }
Exemplo n.º 26
0
        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;
        }
Exemplo n.º 27
0
        void ExportDVHs(PlanSetup plan, StructureSet ss, string[] structureIds, XmlWriter writer)
        {
            writer.WriteStartElement("html");

            writer.WriteStartElement("head");
            writer.WriteElementString("title", "web dvh");
            XElement script = new XElement("script",
                                           new XAttribute("type", "text/javascript"),
                                           new XAttribute("src", "https://www.google.com/jsapi"),
                                           "// need this due to bug in google LineChart javascript"
                                           );

            script.WriteTo(writer);
            script = new XElement("script",
                                  new XAttribute("type", "text/javascript"),
                                  @"
        google.load('visualization', '1', { packages: ['corechart'] });
");
            script.WriteTo(writer);
            Tuple <string, DVHData>[] listDVHs = new Tuple <string, DVHData> [structureIds.Length];
            int index = 0, maxPtsIndex = 0;
            int maxDVHPts = int.MinValue;
            // search through the list of structure ids until we find one
            Structure structure = null;

            foreach (string volumeId in structureIds)
            {
                structure = (from s in ss.Structures
                             where s.Id.ToUpper().CompareTo(volumeId.ToUpper()) == 0
                             select s).FirstOrDefault();

                if (structure == null)
                {
                    continue; // structure not found
                }
                DVHData dvh = plan.GetDVHCumulativeData(structure, DoseValuePresentation.Absolute, VolumePresentation.Relative, 0.1);
                listDVHs[index] = new Tuple <string, DVHData>(volumeId, dvh);
                if (maxDVHPts < dvh.CurveData.Count())
                {
                    maxPtsIndex = index;
                }
                maxDVHPts = Math.Max(maxDVHPts, dvh.CurveData.Count());
                index++;
            }
            // collect the dose / volume data into a single matrix
            double [,] dvhData = new double[maxDVHPts, listDVHs.Count()];
            for (int j = 0; j < listDVHs.Count(); j++)
            {
                for (int i = 0; i < maxDVHPts; i++)
                {
                    dvhData[i, j] = 0.0;
                    DVHData dvh = listDVHs[j].Item2;
                    if (dvh.CurveData.Count() > i)
                    {
                        dvhData[i, j] = dvh.CurveData[i].Volume;
                    }
                }
            }
            string javascript = @"
        function drawVisualization() {
          var data = google.visualization.arrayToDataTable([
            ['Dose'";

            foreach (Tuple <string, DVHData> dvhItemData1 in listDVHs)
            {
                javascript += ", '" + dvhItemData1.Item1 + "'";
            }
            javascript += @"],
";
            int x = 0;

            foreach (DVHPoint pt in listDVHs[maxPtsIndex].Item2.CurveData)
            {
                string doseVolumes = string.Format("[{0:0.0}", pt.DoseValue.Dose);
                for (int j = 0; j < listDVHs.Count(); j++)
                {
                    doseVolumes += string.Format(",{0:0.00000}", dvhData[x, j]);
                }
                doseVolumes += @"],";
                javascript  += doseVolumes;
                x++;
            }
            javascript += @"
        ]);

            // Create and draw the visualization.
            new google.visualization.LineChart(document.getElementById('xxxxx')).
            draw(data, {
                width: 1000, height: 800,
                vAxis: { maxValue: 100 }
            }
                );
        }


        google.setOnLoadCallback(drawVisualization);
";
            XElement script2 = new XElement("script",
                                            new XAttribute("type", "text/javascript"),
                                            javascript
                                            );

            script2.WriteTo(writer);

            writer.WriteEndElement();// head

            XElement body = new XElement("body",
                                         new XElement("div",
                                                      new XAttribute("id", "xxxxx"),
                                                      new XAttribute("style", "width: 900px; height: 500px;")
                                                      ));

            body.WriteTo(writer);
            writer.WriteEndElement();// html
        }