Exemplo n.º 1
0
 /// <summary>
 /// Creates a new array slice that refers to <paramref name="count"/> elements in the given <paramref name="containingArray"/>,
 /// starting from the element at index <paramref name="offset"/>.
 /// </summary>
 /// <param name="containingArray">The array to represent. Must not be null.</param>
 /// <param name="offset">The index of the first element in <paramref name="containingArray"/> to include in this slice.</param>
 /// <param name="count">The number of elements in <paramref name="containingArray"/> to include in this slice.</param>
 public ArraySlice(T[] containingArray, uint offset, uint count)
 {
     Assure.NotNull(containingArray);
     Assure.LessThanOrEqualTo(
         offset + count,
         containingArray.Length,
         "offset + count must be less than or equal to the containing array's length."
         );
     this.ContainingArray = containingArray;
     this.Offset          = offset;
     this.Length          = count;
 }
Exemplo n.º 2
0
        public void TestLessThanOrEqualTo()
        {
            // Define variables and constants
            const int FIVE = 5;
            const int FOUR = 4;

            // Set up context


            // Execute
            Assure.LessThanOrEqualTo(FOUR, FIVE);
            Assure.LessThanOrEqualTo(FOUR, FOUR);
            try {
                Assure.LessThanOrEqualTo(FIVE, FOUR);
                Assert.Fail();
            }
            catch (AssuranceFailedException) {
            }

            // Assert outcome
        }
Exemplo n.º 3
0
 /// <summary>
 /// Gets the radius of the circle taken by slicing through this sphere at the given distance from its centre.
 /// </summary>
 /// <param name="distanceFromCentre">The distance from the centre to get the slice's radius for.</param>
 /// <returns>The radius of the circle at the given distance from the sphere's centre.</returns>
 /// <exception cref="AssuranceFailedException">Thrown if <paramref name="distanceFromCentre"/> is greater than
 /// <see cref="Radius"/>.</exception>
 public float GetRadius(float distanceFromCentre)
 {
     Assure.LessThanOrEqualTo(distanceFromCentre, Radius, "Distance from centre must be smaller than or equal to the sphere radius!");
     return((float)Math.Sqrt((Radius * Radius) - (distanceFromCentre * distanceFromCentre)));
 }