Exemple #1
0
        public void SoldAverage___Example()
        {
            var expectedHash = new Dictionary <string, AverageResult>();
            var props        = new List <PropertyInfo>();

            var postalCode  = string.Empty;
            var postalCount = new Dictionary <string, double>();

            //var expectedOutputSection = false;
            foreach (var l in FileIO.ReadFrom(@"data\soldaverage_example.txt"))
            {
                var line         = l.Trim();
                var upper        = line.ToUpper();
                var upperNoSpace = upper.Replace(" ", string.Empty);
                if (upperNoSpace.StartsWith("HOUSE#"))
                {
                    var prop = ExtractPropInfo(line);
                    props.Add(prop);
                    if (postalCount.ContainsKey(prop.PostalCode))
                    {
                        postalCount[prop.PostalCode]++;
                    }
                    else
                    {
                        postalCount.Add(prop.PostalCode, 1);
                    }
                }
                else if (upperNoSpace.StartsWith("ZIPCODE:"))
                {
                    var index = line.IndexOf(':');
                    postalCode = line.Substring(index + 1).Trim();
                    //expectedOutputSection = true;

                    var expected = new AverageResult(postalCode);
                    expectedHash.Add(postalCode, expected);
                    if (postalCount.ContainsKey(postalCode))
                    {
                        expected.Count = postalCount[postalCode];
                    }
                }
                else if (upperNoSpace.StartsWith("AVERAGEPRICEPRIORTOFLIP:"))
                {
                    var index       = line.IndexOf(':');
                    var priceBefore = line.Substring(index + 1).Trim();
                    var expected    = expectedHash[postalCode];
                    expected.BeforePrice = ConvertPrice(priceBefore);
                    Console.WriteLine("FOUND#1:" + expected.BeforePrice);
                }
                else if (upperNoSpace.StartsWith("AVERAGEPRICEAFTERFLIP:"))
                {
                    var index      = line.IndexOf(':');
                    var priceAfter = line.Substring(index + 1).Trim();
                    var expected   = expectedHash[postalCode];
                    expected.AfterPrice = ConvertPrice(priceAfter);
                    Console.WriteLine("FOUND#2:" + expected.AfterPrice);
                }
            }

            var hash = sut.Average(props);

            foreach (var k in expectedHash.Keys)
            {
                postalCode = k;
                Console.WriteLine("For postal code: '{0}'", postalCode);

                var expected = expectedHash[k];
                var result   = hash[k];

                Console.WriteLine("Expected: \r\n {0}", expected);
                Console.WriteLine("Actual: \r\n {0}", result);
                Assert.AreEqual(expected, result);
                Console.WriteLine("(PASSED)");
                Console.WriteLine("--------------------------------------------------");
            }
        }
Exemple #2
0
    {    // ORACLE
        public virtual Dictionary <string, AverageResult> Average(List <PropertyInfo> properties)
        {
            /*
             * string postalCode = null;
             * double priceBefore=0, priceAfter=0;
             * double sqftBefore=0, sqftAfter=0;
             * double bedsBefore=0, bedsAfter=0;
             * double bathsBefore=0, bathsAfter=0;
             * double count=0;
             * foreach(var p in properties)
             * {
             ++count;
             *      priceBefore+=p.BeforePrice; priceAfter+=p.AfterPrice;
             *      sqftBefore+=p.BeforeSqft; sqftAfter+=p.AfterSqft;
             * bedsBefore+=p.BeforeBeds; bedsAfter+=p.AfterBeds;
             * bathsBefore+=p.BeforeBaths; bathsAfter+=p.AfterBaths;
             * }
             *
             * double BeforePriceAvg=priceBefore/count, AfterPriceeAvg=priceAfter/count;
             * double BeforeSqfteAvg=sqftBefore/count, AfterSqfteAvg=sqftAfter/count;
             * double BeforeBedseAvg=bedsBefore/count, AfterBedseAvg=bedsAfter/count;
             * double BeforeBathseAvg=bathsBefore/count, AfterBathseAvg=bathsAfter/count;
             *
             * return new AverageResult(
             * postalCode,
             * BeforePriceAvg, AfterPriceeAvg,
             * BeforeSqfteAvg, AfterSqfteAvg,
             * BeforeBedseAvg, AfterBedseAvg,
             * BeforeBathseAvg, AfterBathseAvg
             * );
             */
            var hash = new Dictionary <string, AverageResult>();

            foreach (var p in properties)
            {
                var           postalCode = p.PostalCode;
                AverageResult avgRes     = null;
                if (hash.ContainsKey(postalCode))
                {
                    avgRes = hash[postalCode];
                }
                else
                {
                    avgRes = new AverageResult(postalCode)
                    {
                        Count = 0
                    };
                    hash.Add(postalCode, avgRes);
                }
                avgRes.Count++; Console.WriteLine("{0} Count: {1}", postalCode, avgRes.Count);
                avgRes.BeforePrice += p.BeforePrice; avgRes.AfterPrice += p.AfterPrice;
                avgRes.BeforeSqft  += p.BeforeSqft; avgRes.AfterSqft += p.AfterSqft;
                avgRes.BeforeBeds  += p.BeforeBeds; avgRes.AfterBeds += p.AfterBeds;
                avgRes.BeforeBaths += p.BeforeBaths; avgRes.AfterBaths += p.AfterBaths;
            }

            foreach (AverageResult avgRes in hash.Values)
            {
                avgRes.BeforePrice /= avgRes.Count; avgRes.AfterPrice /= avgRes.Count;
                avgRes.BeforeSqft  /= avgRes.Count; avgRes.AfterSqft /= avgRes.Count;
                avgRes.BeforeBeds  /= avgRes.Count; avgRes.AfterBeds /= avgRes.Count;
                avgRes.BeforeBaths /= avgRes.Count; avgRes.AfterBaths /= avgRes.Count;
            }
            return(hash);
        }