The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 364 Weeks Ago, 4 Days Ago |
| Questions Answered: | 1850 |
| Tutorials Posted: | 1850 |
Graduate in Biology and Nutrition, MBA Finance
Florida State University
Aug-2000 - Jul-2007
Ass. Relationship Manager
Penn-Florida
Mar-2009 - Feb-2016
In this week's team sprint assignment I need to complete two tasks (tasks 3 and 4 below). We need to add code to an existing unit test to set the input parameters for the function to be tested, and set the expected variable(s) for the value to be returned. The code is already there to compare your expected value to the actual value returned by the function being tested. The code to load the array values for Hubs has been moved into its own function so that the unit tests will work correctly and to pave the way for next week's sprint. If you get stuck modifying your own unit test, you may want to look at the unit test, ValueOfTest1, for inspiration, since this unit test has been completed for you. Notice that the call to the Assert.Inconclusive method has been commented out.Story: As a system administrator, I want a unit testing framework for easier testing and independence when writing code. My tasks are relatively simple, but I'm having trouble writing the code correctly.
Â
Task 3:Â Â Â Â Â Â Â Â Â Â Add a unit test for the CoordinateToDegrees function to assure that coordinates are transformed to decimal degrees correctly.
Task 3a: Â Â Â Â Â Â Â Â Right click anywhere within the CoordinateToDegrees function in Airports.vb and add a unit test named CoordinateToDegreesTest to the unit test framework. (This has been done for you.)
Task3b: Modify the code in CoordinateToDegreesTest to assert that
DegreeString =  "33° 38' 22"" N" and set the expected value to 33.63944.
You will need to set delta, the third parameter of the assert.equal function, to .00001 to allow for rounding error.
Task 3c: Run the unit tests to make sure they all pass.
Task 3d: Â Â Â Â Â Â Â Â Check out the master copy of the project and install your changes.
Â
Task 4:Â Â Â Â Â Â Â Â Â Â Add a unit test for the DegreesToRadians function to assure that coordinates are transformed to radians correctly.
Task 4a: Â Â Â Â Â Â Â Â Right click anywhere within the CoordinateToDegrees function in Airports.vb and add a unit test named DegreesToRadiansTest to the unit test framework. (This has been done for you.)
Task4b: Modify the code in DegreesToRadiansTest to assert that DegreesDouble = 33.63944
and set the expected value to 0.58712. You will need to set delta, the third parameter of the assert.equal function, to .00001 to allow for rounding error.
Task 4c: Run the unit tests to make sure they all pass.
Task 4d: Â Â Â Â Â Â Â Â Check out the master copy of the project and install your changes.
Â
This is our project code so far...
Â
Test Code:
'''<summary>
'''This is a test class for AirportsTest and is intended
'''to contain all AirportsTest Unit Tests
'''</summary>
<TestClass()> _
Public Class AirportsTest
   Private testContextInstance As TestContext
   '''<summary>
   '''Gets or sets the test context which provides
   '''information about and functionality for the current test run.
   '''</summary>
   Public Property TestContext() As TestContext
       Get
           Return testContextInstance
       End Get
       Set(ByVal value As TestContext)
           testContextInstance = Value
       End Set
   End Property
#Region "Additional test attributes"
   '
   'You can use the following additional attributes as we write tests:
   '
   'Use ClassInitialize to run code before running the first test in the class
   '<ClassInitialize()> _
   '
   'Public Shared Sub MyClassInitialize(ByVal testContext As TestContext)
   'End Sub
   '
   'Use ClassCleanup to run code after all tests in a class have run
   '<ClassCleanup()> _
   'Public Shared Sub MyClassCleanup()
   'End Sub
   '
   'Use TestInitialize to run code before running each test
   '<TestInitialize()> _
   'Public Sub MyTestInitialize()
   'End Sub
   '
   'Use TestCleanup to run code after each test has run
   '<TestCleanup()> _
   'Public Sub MyTestCleanup()
   'End Sub
   '
#End Region
   '''<summary>
   '''A test for CoordinateToDegrees
   '''</summary>
   <TestMethod()> _
   Public Sub CoordinateToDegreesTest()
       Dim target As Airports = New Airports() ' TODO: Initialize to an appropriate value
       Dim DegreeString As String = String.Empty ' TODO: Initialize to an appropriate value
       Dim expected As Double = 0.0! ' TODO: Initialize to an appropriate value
       Dim delta As Double = 0.0! ' TODO: Initialize to an appropriate value
       Dim actual As Double
       actual = target.CoordinateToDegrees(DegreeString)
       Assert.AreEqual(expected, actual, delta)
       Assert.Inconclusive("Verify the correctness of this test method.")
   End Sub
   '''<summary>
   '''A test for DegreesToRadians
   '''</summary>
   <TestMethod()> _
   Public Sub DegreesToRadiansTest()
       Dim target As Airports = New Airports() ' TODO: Initialize to an appropriate value
       Dim DegreesDouble As Double = 0.0! ' TODO: Initialize to an appropriate value
       Dim expected As Double = 0.0! ' TODO: Initialize to an appropriate value
       Dim delta As Double = 0.0! ' TODO: Initialize to an appropriate value
       Dim actual As Double
       actual = target.DegreesToRadians(DegreesDouble)
       Assert.AreEqual(expected, actual, delta)
       Assert.Inconclusive("Verify the correctness of this test method.")
   End Sub
   '''<summary>
   '''A test for Distance
   '''</summary>
   <TestMethod()> _
   Public Sub DistanceTest()
       Dim target As Airports = New Airports() ' TODO: Initialize to an appropriate value
       Dim Index1 As Integer = 0 ' TODO: Initialize to an appropriate value
       Dim Index2 As Integer = 0 ' TODO: Initialize to an appropriate value
       Dim expected As Double = 0.0! ' TODO: Initialize to an appropriate value
       Dim delta As Double = 0.0! ' TODO: Initialize to an appropriate value
       Dim actual As Double
       actual = target.Distance(Index1, Index2)
       Assert.AreEqual(expected, actual, delta)
       Assert.Inconclusive("Verify the correctness of this test method.")
   End Sub
   '''<summary>
   '''A test for ValueOf (City)
   '''</summary>
   <TestMethod()> _
   Public Sub ValueOfTest1()
       Dim target As Airports = New Airports() ' TODO: Initialize to an appropriate value
       Dim Index As Integer = 0 ' TODO: Initialize to an appropriate value
       Dim FieldName As Airports.FieldNames = New Airports.FieldNames() ' TODO: Initialize to an appropriate value
       Dim expected As String = String.Empty ' TODO: Initialize to an appropriate value
       Dim actual As String
       target.LoadData()
       Index = 0
       FieldName = Airports.FieldNames.City
       expected = "Atlanta"
       actual = target.ValueOf(Index, FieldName)
       Assert.AreEqual(expected, actual)
       'Assert.Inconclusive("Verify the correctness of this test method.")
   End Sub
   '''<summary>
   '''A test for ValueOf (Latitude)
   '''</summary>
   <TestMethod()> _
   Public Sub ValueOfTest2()
       Dim target As Airports = New Airports() ' TODO: Initialize to an appropriate value
       Dim Index As Integer = 0 ' TODO: Initialize to an appropriate value
       Dim FieldName As Airports.FieldNames = New Airports.FieldNames() ' TODO: Initialize to an appropriate value
       Dim expected As String = String.Empty ' TODO: Initialize to an appropriate value
       Dim actual As String
       target.LoadData()
       Debug.Assert(Index = 0)
       Debug.Assert(FieldName = Airports.FieldNames.Lat)
       actual = target.ValueOf(Index, FieldName)
       Assert.AreEqual(expected, actual)
       Assert.Inconclusive("Verify the correctness of this test method.")
   End Sub
   '''<summary>
   '''A test for ValueOf (Longitude)
   '''</summary>
   <TestMethod()> _
   Public Sub ValueOfTest3()
       Dim target As Airports = New Airports() ' TODO: Initialize to an appropriate value
       Dim Index As Integer = 0 ' TODO: Initialize to an appropriate value
       Dim FieldName As Airports.FieldNames = New Airports.FieldNames() ' TODO: Initialize to an appropriate value
       Dim expected As String = String.Empty ' TODO: Initialize to an appropriate value
       Dim actual As String
       actual = target.ValueOf(Index, FieldName)
       Assert.AreEqual(expected, actual)
       Assert.Inconclusive("Verify the correctness of this test method.")
   End Sub
End Class
Main Form Code:
Option Strict On
Option Explicit On
Imports System.Math
Public Class Airports
   Public Enum FieldNames
       ID = 0
       City = 1
       Lat = 2
       Lon = 3
   End Enum
   Structure Airport 'Record
       Dim ID As String
       Dim City As String
       Dim Lat As String
       Dim Lon As String
   End Structure
   'Internal variables for current Airport records
   Dim Index1Integer As Integer
   Dim Lat1Double As Double
   Dim Lon1Double As Double
   Dim Index2Integer As Integer
   Dim Lat2Double As Double
   Dim Lon2Double As Double
   'Array of all Airport records
   Dim Hubs(3) As Airport
   Private Sub Form1_Load(ByVal sender As Object, _
              ByVal e As System.EventArgs) Handles Me.Load
       LoadData()
   End Sub
   Public Sub LoadData()
       '  The following code was moved from the Me.Load Event Handler
       '  for use in unit testing
       'Load small sample of airport hubs into Hubs array
       Hubs(0).ID = "ATL"
       Hubs(0).City = "Atlanta"
       Hubs(0).Lat = "33° 38' 22"" N"
       Hubs(0).Lon = "84° 25' 41"" W"
       Hubs(1).ID = "BOS"
       Hubs(1).City = "Boston"
       Hubs(1).Lat = "42° 21' 42"" N"
       Hubs(1).Lon = "71° 0' 42"" W"
       Hubs(2).ID = "CLE"
       Hubs(2).City = "Cleveland"
       Hubs(2).Lat = "41° 24' 27"" N"
       Hubs(2).Lon = "81° 51' 4"" W"
       Hubs(3).ID = "SEA"
       Hubs(3).City = "Seattle"
       Hubs(3).Lat = "47° 26' 56"" N"
       Hubs(3).Lon = "122° 18' 33"" W"
       'Load ID1ComboBox List
       For IndexInteger As Integer = 0 To 2
           ID1ComboBox.Items.Add(Hubs(IndexInteger).ID)
       Next
       'Load ID2ComboBox List
       For IndexInteger As Integer = 0 To 2
           ID2ComboBox.Items.Add(Hubs(IndexInteger).ID)
       Next
       'Set default values for Combo boxes
       ID1ComboBox.SelectedIndex = 0
       ID2ComboBox.SelectedIndex = 1
   End Sub
   Public Function CoordinateToDegrees(ByVal DegreeString As String) As Double
       '  Converts a coordinate string in degree/minute/second notation to decimal degrees.
       Dim degrees As Double
       Dim minutes As Double
       Dim seconds As Double
       Dim StartPtr, StopPtr As Integer
       StartPtr = 0
       StopPtr = DegreeString.IndexOf("°", StartPtr)
       degrees = Convert.ToDouble(DegreeString.Substring(StartPtr, StopPtr - StartPtr))
       StartPtr = StopPtr + 1
       StopPtr = DegreeString.IndexOf("'", StartPtr)
       minutes = Convert.ToDouble(DegreeString.Substring(StartPtr, StopPtr - StartPtr))
       StartPtr = StopPtr + 1
       StopPtr = DegreeString.IndexOf("""", StartPtr)
       seconds = Convert.ToDouble(DegreeString.Substring(StartPtr, StopPtr - StartPtr))
       '1 degree = 60 minutes = 3600 seconds
       '1 minute = 60 seconds
       Return degrees + minutes / 60.0 + seconds / 3600.0
   End Function
   Function DegreesToRadians(ByVal DegreesDouble As Double) As Double
       '  converts decimal degrees to radians
       '  Convert angles to radians
       '  180 degrees = Pi radians
       Return DegreesDouble * PI / 180
   End Function
   Public Function ValueOf(ByVal Index As Integer, ByVal FieldName As FieldNames) As String
       '  Extract airport information from the Hubs array
       If FieldName = FieldNames.City Then
           Return Hubs(Index).City
       ElseIf FieldName = FieldNames.Lat Then
           Return Hubs(Index).Lat
       ElseIf FieldName = FieldNames.Lon Then
           Return Hubs(Index).Lon
       Else
           Return ""
       End If
   End Function
   Public Function Distance(ByVal Index1 As Integer, ByVal Index2 As Integer) As Double
       '
       'Calculate the distance in miles between the two cities selected in the combo boxes after their latitudes and longitudes
       'have been converted to decimal fractions
       '
       'Spherical law of cosines: Â
       'Anton von Braunmühl, Vorlesungen über Geschichte der Trigonometrie, Vol. 1, 1900
       '
       Const R As Double = 3958.761 'mean Earth radius in miles
       Dim Lat1, Lat2, Lon1, Lon2, d As Double
       Lat1 = DegreesToRadians(CoordinateToDegrees(Hubs(Index1).Lat))
       Lat2 = DegreesToRadians(CoordinateToDegrees(Hubs(Index2).Lat))
       Lon1 = DegreesToRadians(CoordinateToDegrees(Hubs(Index1).Lon))
       Lon2 = DegreesToRadians(CoordinateToDegrees(Hubs(Index2).Lon))
        'd = acos(sin(lat1) • sin(lat2) + cos(lat1) • cos(lat2) • cos(long2 − long1)) • R
       d = Acos(Sin(Lat1) * Sin(Lat2) + Cos(Lat1) * Cos(Lat2) * Cos(Lon2 - Lon1)) * R
       Return d
   End Function
   Private Sub ID1ComboBox_SelectedIndexChanged(ByVal sender As System.Object, _
               ByVal e As System.EventArgs) Handles ID1ComboBox.SelectedIndexChanged
       '
       'Load Cit1TextBox, Lat1TextBox, Lon1TextBox with values from the array Airports(ID1Integer)
       '
       Index1Integer = ID1ComboBox.SelectedIndex
       City1TextBox.Text = Hubs(Index1Integer).City
       Lat1TextBox.Text = Hubs(Index1Integer).Lat
       Lon1TextBox.Text = Hubs(Index1Integer).Lon
   End Sub
   Private Sub ID2ComboBox_SelectedIndexChanged(ByVal sender As System.Object, _
               ByVal e As System.EventArgs) Handles ID2ComboBox.SelectedIndexChanged
       '
       'Load Cit2TextBox, Lat2TextBox, Lon2TextBox with values from the array Airports(ID2Integer)
       '
       Index2Integer = ID2ComboBox.SelectedIndex
       City2TextBox.Text = Hubs(Index2Integer).City
       Lat2TextBox.Text = Hubs(Index2Integer).Lat
       Lon2TextBox.Text = Hubs(Index2Integer).Lon
   End Sub
   Private Sub CalcDistanceButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalcDistanceButton.Click
       DistanceTextBox.Text = Distance(Index1Integer, Index2Integer).ToString("F0")
   End Sub
End Class
Attachments:Hel-----------lo -----------Sir-----------/Ma-----------dam----------- Â----------- -----------Tha-----------nk -----------you----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------acq-----------uis-----------iti-----------on -----------of -----------my -----------pos-----------ted----------- so-----------lut-----------ion-----------.Pl-----------eas-----------e p-----------ing----------- me----------- on----------- ch-----------at -----------I a-----------m Â----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I