rtest03.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #!/bin/bash
  2. rm -f X1 X2 X3 X1.txt X2.txt X3.txt
  3. cat > X1.txt << EOF
  4. 1 12
  5. A 1 2 1000 1
  6. A 1 3 20 2
  7. A 1 4 21 8
  8. A 1 5 8 9
  9. A 3 4 1 10
  10. A 3 5 100 11
  11. A 3 11 100 12
  12. A 2 80 8 13
  13. A 2 81 22 14
  14. A 2 5 7 15
  15. A 3 1 22 16
  16. A 3 80 10 17
  17. A 4 5 10 18
  18. A 10 20 10 1020
  19. A 10 30 10 1030
  20. A 10 40 10 1040
  21. A 20 30 10 2030
  22. A 30 40 10 3040
  23. A 40 50 10 4050
  24. A 40 60 10 4060
  25. A 60 50 10 6050
  26. EOF
  27. cat > X2.txt << EOF
  28. 2 12
  29. A 1 2 1000 1
  30. A 1 3 20 2
  31. A 1 4 21 8
  32. A 1 5 8 9
  33. A 3 4 1 10
  34. A 3 5 100 11
  35. A 3 11 100 12
  36. A 2 80 8 13
  37. A 2 81 22 14
  38. A 2 5 7 15
  39. A 3 1 22 16
  40. A 3 80 10 17
  41. A 4 5 10 18
  42. A 10 20 10 1020
  43. A 10 30 10 1030
  44. A 10 40 10 1040
  45. A 20 30 10 2030
  46. A 30 40 10 3040
  47. A 40 50 10 4050
  48. A 40 60 10 4060
  49. A 60 50 10 6050
  50. EOF
  51. cat > X3.txt << EOF
  52. 3 12
  53. A 1 2 1000 1
  54. A 1 3 20 2
  55. A 1 4 21 8
  56. A 1 5 8 9
  57. A 3 4 1 10
  58. A 3 5 100 11
  59. A 3 11 100 12
  60. A 2 80 8 13
  61. A 2 81 22 14
  62. A 2 5 7 15
  63. A 3 1 22 16
  64. A 3 80 10 17
  65. A 4 5 10 18
  66. A 10 20 10 1020
  67. A 10 30 10 1030
  68. A 10 40 10 1040
  69. A 20 30 10 2030
  70. A 30 40 10 3040
  71. A 40 50 10 4050
  72. A 40 60 10 4060
  73. A 60 50 10 6050
  74. EOF
  75. function check_path () {
  76. fromNode=$1
  77. toNode=$2
  78. totDistance=$3
  79. nLinks=$4
  80. nodeList=($5)
  81. file=$6
  82. echo "check_path $fromNode -> $toNode - tot. distance $totDistance - n. links $nLinks"
  83. vlist=(`./shortest_path -g $file -f $fromNode -t $toNode`) || { echo "compute shortest path: command execution failed."; exit 1; }
  84. test "${vlist[10]}" = "unreachable" && {
  85. echo "node $toNode is unreachable - test failed"; exit 1
  86. }
  87. test "${vlist[12]}" = "$nLinks" || {
  88. echo "link count is ${vlist[12]} instead of $nLinks - test failed"; exit 1
  89. }
  90. test "${vlist[16]}" = "$totDistance" || {
  91. echo "total distance is ${vlist[16]} instead of $totDistance - test failed"; exit 1
  92. }
  93. i=19
  94. iNodeList=0
  95. for (( iLink=0 ; iLink < $nLinks ; iLink++ ))
  96. do
  97. test ! "${vlist[$i]}" == "${nodeList[$iNodeList]}" && {
  98. echo "wrong link $iLink head (${vlist[$i]}, ${nodeList[$iNodeList]}) - test failed"; exit 1
  99. }
  100. let i=i+2
  101. let iNodeList=iNodeList+1
  102. test ! "${vlist[$i]}" == "${nodeList[$iNodeList]}" && {
  103. echo "wrong link $iLink tail (${vlist[$i]}, ${nodeList[$iNodeList]}) - test failed"; exit 1
  104. }
  105. let i=i+17
  106. let iNodeList=iNodeList+1
  107. done
  108. echo "done"
  109. }
  110. #
  111. #
  112. #
  113. echo "script rtest03.sh: test shortest path computations..."
  114. ./cr_from_a -f X1.txt -g X1 || { echo "create test graph: command execution failed."; exit 1; }
  115. check_path 1 80 30 2 "1 3 3 80" X1 || exit 1
  116. check_path 3 1 22 1 "3 1" X1 || exit 1
  117. ./cr_from_a -f X2.txt -g X2 || { echo "create test graph: command execution failed."; exit 1; }
  118. check_path 1 80 30 2 "1 3 3 80" X2 || exit 1
  119. check_path 3 1 22 1 "3 1" X2 || exit 1
  120. echo "script done"
  121. rm -f X1 X2 X3 X1.txt X2.txt X3.txt
  122. exit 0