pittmesh / ip-calculator

A browser-based calculator for determining PittMesh IP addresses
http://www.pittmesh.net/ipcalc
1 stars 0 forks source link

Initial commit - Added bash version of mac2ip calculator #4

Closed jasonkhanlar closed 8 years ago

colindean commented 8 years ago

Can you change the commit summary to be something more indicative of the content of the commit? E.g. "Adds bash version of calculator" or something like that.

jasonkhanlar commented 8 years ago

thump

colindean commented 8 years ago

Almost there!

jasonkhanlar commented 8 years ago

_s_h_a_ke

colindean commented 8 years ago

Great work! Next (optional) step? Write a simple test script that checks the known good output of a few inputs.

jasonkhanlar commented 8 years ago

What kind of inputs? What determines known good outputs?

colindean commented 8 years ago

If you know that the MAC address de:ad:be:ef:00:01 will always produce an IP of 100.64.87.1, then that's a test case†. Pick another three or four, figure them out by hand. Call the script and check its output for what you'd expect.

script_to_test=./mm-commotion-mac2ip
failure=0

test() {
  local mac=$1
  local ip=$2

  if [[ "$($script_to_test $mac)" != "$ip" ]]; then
    echo "$mac did not resolve to $ip"
    failure=1
  fi
}

test "de:ad:be:ef:00:01" "100.64.87.1"
test "d3-4d-B3-3F-10:11" "100.64.87.101"

if [[ $failure -gt 0 ]]; then 
  echo "There were failures."
  exit 1
fi
}

This eventually leads to a sort of generative test, where you can generate applicable MAC addresses at random and check the output against a known working implementation. This last bit is probably more work that is worth it for now, though.

† The MACs and IPs mentioned in this post are certainly not correctly paired.