Don't like ads? PRO users don't see any ads ;-)
Guest

multiplication_commutative_test

By: waterapple on Jul 11th, 2013  |  syntax: Python  |  size: 1.28 KB  |  hits: 42  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #-------------------------------------------------------------------------------
  2. # Name:        multiplication_commutative_test
  3. # Purpose:      Prove that any order of multiplying the same vales results
  4. #               in the same answer
  5. #
  6. # Author:      new
  7. #
  8. # Created:     11/07/2013
  9. # Copyright:   (c) new 2013
  10. # Licence:     <your licence>
  11. #-------------------------------------------------------------------------------
  12. #!/usr/bin/env python
  13.  
  14.  
  15. def test_multiplication_commutative(start_int,stop_int):
  16.     for int_one in xrange(start_int,stop_int):
  17.         for int_two in xrange(start_int,stop_int):
  18.             for int_three in xrange(start_int,stop_int):
  19.                 print "testing :", int_one, int_two, int_three,
  20.                 all_same = (
  21.                 (int_one * int_two * int_three) == # 123
  22.                 (int_one * int_three * int_two) == # 132
  23.                 (int_two * int_one * int_three) == # 213
  24.                 (int_two * int_three * int_one) == # 231
  25.                 (int_three * int_two * int_one) == # 312
  26.                 (int_three * int_one * int_two)    # 321
  27.                 )
  28.                 print all_same
  29.                 assert(all_same)
  30.  
  31.  
  32. def main():
  33.     test_multiplication_commutative(1,1000)
  34.  
  35. if __name__ == '__main__':
  36.     main()