コード例 #1
0
ファイル: CircusTower.cs プロジェクト: mmoroney/Algorithms
        private static int TopDown(Person[] people)
        {
            int[] counts = new int[people.Length];
            int max = int.MinValue;

            for(int i = 0; i < counts.Length; i++)
                max = Math.Max(max, CircusTower.GetCount(people, i, counts));

            return max;
        }
コード例 #2
0
ファイル: ExcludeTests.cs プロジェクト: vnvizitiu/AOP
        public void WhenAppliedToClassWithNoExcludeShouldLogPropertyAndConstructor()
        {
            // act
            Person person = new Person
            {
                Name = Guid.NewGuid().ToString()
            };
            person.Name.Should().NotBeNullOrWhiteSpace();

            // assert
            _logger.DebugCallCount.Should()
                .Be(9, "because we hit the Entry, Success and Exit methods for both constructor and property");
        }
コード例 #3
0
ファイル: CircusTower.cs プロジェクト: mmoroney/Algorithms
        private static int GetCount(Person[] people, int i, int[] counts)
        {
            if (counts[i] > 0)
                return counts[i];

            counts[i] = 1;

            for (int j = 0; j < people.Length; j++)
            {
                if (people[i].CanStandOn(people[j]))
                    counts[i] = Math.Max(counts[i], CircusTower.GetCount(people, j, counts) + 1);
            }

            return counts[i];
        }
コード例 #4
0
ファイル: CircusTower.cs プロジェクト: mmoroney/Algorithms
        private static int BottomUp(Person[] people)
        {
            int[] counts = new int[people.Length];

            for(int i = 0; i < counts.Length; i++)
            {
                for(int j = 0; j < counts.Length; j++)
                {
                    for(int k = 0; k < counts.Length; k++)
                    {
                        if (people[j].CanStandOn(people[k]))
                            counts[j] = Math.Max(counts[j], counts[k] + 1);
                    }
                }
            }

            return counts.Max() + 1;
        }
コード例 #5
0
ファイル: CircusTower.cs プロジェクト: mmoroney/Algorithms
        public void CircusTowerTest()
        {
            Func<Person[], int>[] functions = new Func<Person[], int>[]
            {
                CircusTower.BottomUp,
                CircusTower.TopDown
            };

            Random random = new Random();
            for (int i = 0; i < 10; i++)
            {
                Person[] people = new Person[15];
                for(int j = 0; j < 15; j++)
                    people[j] = new Person { Height = random.Next(3, 8), Weight = random.Next(80, 300) };

                Tests.TestFunctions(people, functions);
            }
        }
コード例 #6
0
 public void SetPerson(Person[] value)
 {
     person = value;
 }
コード例 #7
0
ファイル: CircusTower.cs プロジェクト: mmoroney/Algorithms
 public bool CanStandOn(Person p)
 {
     return p.Height > this.Height && p.Weight > this.Weight;
 }
コード例 #8
0
        /// <summary>
        /// This method parse the Person Lookup data to class Result.
        /// </summary>
        /// <param name="responseInJson">responseInJson</param>
        /// <returns>Result</returns>
        private Result ParsePersonLookupResult(string responseInJson)
        {
            // Creating Result class to fill the person lookup data.
            Result result = new Result();

            try
            {
                // Creating list of Person class to fill the person lookup data.
                List<Person> personList = new List<Person>();

                // responseInJson to DeserializeObject
                dynamic jsonObject = JsonConvert.DeserializeObject(responseInJson);

                if (jsonObject != null)
                {
                    // Take the dictionary object from jsonObject.
                    dynamic dictionaryObj = jsonObject.dictionary;
                    if (dictionaryObj != null)
                    {
                        List<string> personKeyList = new List<string>();

                        // Creating list of all person key from result node of jsonObject.
                        foreach (var data in jsonObject.results)
                        {
                            personKeyList.Add(data.Value);
                        }

                        if (personKeyList.Count > 0)
                        {
                            Person personData = null;

                            foreach (string personKey in personKeyList)
                            {
                                personData = new Person();

                                // Extact person object for specific person key.
                                dynamic personKeyObject = dictionaryObj[personKey];
                                if (personKeyObject != null)
                                {
                                    // Extact person name from personKeyObject.
                                    personData.PersonName = (string)personKeyObject["best_name"];

                                    // Extact ageRangeObject from personKeyObject.
                                    dynamic ageRangeObject = personKeyObject["age_range"];

                                    if (ageRangeObject != null)
                                    {
                                        // Extact age range from ageRangeObject.
                                        personData.AgeRange = (string)ageRangeObject["start"];
                                    }

                                    // Extact bestLocationObject from personKeyObject.
                                    dynamic bestLocationObject = personKeyObject["best_location"];
                                    string bestLocationKey = string.Empty;
                                    if (bestLocationObject != null)
                                    {
                                        // Extact bestLocationIdObject from bestLocationObject.
                                        dynamic bestLocationIdObject = bestLocationObject["id"];

                                        if (bestLocationIdObject != null)
                                        {
                                            // Extact location key from bestLocationIdObject.
                                            bestLocationKey = (string)bestLocationIdObject["key"];
                                        }
                                    }

                                    if (!string.IsNullOrEmpty(bestLocationKey))
                                    {
                                        // Extact locationsObject from personKeyObject.
                                        dynamic locationsObject = personKeyObject["locations"];
                                        if (locationsObject != null)
                                        {
                                            foreach (var location in locationsObject)
                                            {
                                                dynamic locationIdObject = location["id"];

                                                if (locationIdObject != null)
                                                {
                                                    // Get location key from locationIdObject.
                                                    string locationKey = (string)locationIdObject["key"];

                                                    if (!string.IsNullOrEmpty(locationKey))
                                                    {
                                                        if (locationKey.ToUpper(CultureInfo.CurrentCulture) == bestLocationKey.ToUpper(CultureInfo.CurrentCulture))
                                                        {
                                                            personData.ContentType = (string)location["contact_type"];
                                                            break;
                                                        }
                                                    }
                                                }
                                            }
                                        }

                                        // Get locationKeyObject from dictionaryObj using bestLocationKey;
                                        dynamic locationKeyObject = dictionaryObj[bestLocationKey];

                                        if (locationKeyObject != null)
                                        {
                                            // Get address line1, line2 and location from locationKeyObject.
                                            personData.AddressLine1 = (string)locationKeyObject["standard_address_line1"];
                                            personData.AddressLine2 = (string)locationKeyObject["standard_address_line2"];
                                            personData.AddressLocation = (string)locationKeyObject["standard_address_location"];

                                            // Get usage from locationKeyObject.
                                            personData.Usage = (string)locationKeyObject["usage"];

                                            // Get isReceivingMail from locationKeyObject.
                                            personData.ReceivingMail = (bool)locationKeyObject["is_receiving_mail"];

                                            // Get deliveryPoint from locationKeyObject.
                                            personData.DeliveryPoint = (string)locationKeyObject["delivery_point"];
                                        }
                                    }

                                    // Adding person lookup data to personList.
                                    personList.Add(personData);
                                }
                            }

                            result.SetPerson(personList.ToArray());
                        }
                        else
                        {
                            this.personResult.Visible = false;
                            this.errorDiv.Visible = true;
                            LitralErrorMessage.Text = WhitePagesConstants.NoResultMessage;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                this.personResult.Visible = false;
                this.errorDiv.Visible = true;
                LitralErrorMessage.Text = ex.Message;
            }

            return result;
        }