예제 #1
0
 /// <summary>
 /// Returns the route of the given two towns.
 /// </summary>
 /// <param name="towns">The towns of the route.</param>
 /// <returns>The route of the towns.</returns>
 private Route GetRoute(TownTuple towns)
 {
     if (_routes.ContainsKey(towns))
     {
         return(_routes[towns]);
     }
     else
     {
         throw new NoSuchRouteException(towns);
     }
 }
        public void ShouldCheckEquality()
        {
            // Arrange
            var ab1 = new TownTuple(new Town('A'), new Town('B'));
            var ab2 = new TownTuple(new Town('A'), new Town('B'));
            var xy  = new TownTuple(new Town('X'), new Town('Y'));

            // Assert
            Assert.AreEqual(ab1, ab2);
            Assert.AreNotEqual(ab1, xy);
        }
        public void ShouldConstruct()
        {
            // Arrange
            var item1 = new Town('A');
            var item2 = new Town('B');

            // Act
            var tuple = new TownTuple(item1, item2);

            // Assert
            Assert.AreEqual(item1, tuple.Item1);
            Assert.AreEqual(item2, tuple.Item2);
        }
예제 #4
0
        /// <summary>
        /// Ctor.
        /// </summary>
        /// <param name="route">A route string in the format "AB5".</param>
        public Route(string route)
        {
            ValidateString(route);

            var item1 = new Town(route[0]);
            var item2 = new Town(route[1]);

            if (item1 == item2)
            {
                throw new MalformedEntityException("The route must be between two different towns.");
            }

            Towns    = new TownTuple(item1, item2);
            Distance = int.Parse(route[2].ToString());
        }
 /// <summary>
 /// Ctor.
 /// </summary>
 /// <param name="townTuple">Route's towns.</param>
 internal NoSuchRouteException(TownTuple towns) :
     base("There isn't a route between towns " + towns.Item1 + " and " + towns.Item2)
 {
 }