tpytestutils.py - sphere - GPU-based 3D discrete element method algorithm with optional fluid coupling
 (HTM) git clone git://src.adamsgaard.dk/sphere
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) LICENSE
       ---
       tpytestutils.py (1833B)
       ---
            1 #!/usr/bin/env python
            2 
            3 from sphere import *
            4 from highlighttext import highlight
            5 import subprocess
            6 import sys
            7 
            8 def passed():
            9     return "\t" + highlight("Passed", "green")
           10 
           11 def failed():
           12     return "\t" + highlight("Failed", "red", True)
           13 
           14 def test(statement, string):
           15     if (statement == True):
           16         print(string + passed())
           17     else:
           18         print(string + failed())
           19         raise Exception("Failed")
           20 
           21 def compare(first, second, string):
           22     returnvalue = (first == second)
           23     if (returnvalue == True or returnvalue > 0):
           24         print(string + passed())
           25     else:
           26         print(string + failed() + ' (' + str(returnvalue) + ')')
           27         raise Exception("Failed")
           28         return(returnvalue)
           29 
           30 def compareFloats(first, second, string, tolerance=1e-3):
           31     #if abs(first-second) < tolerance:
           32     if abs((first-second)/first) < tolerance:
           33         print(string + passed())
           34     else :
           35         print(string + failed())
           36         print("First: " + str(first))
           37         print("Second: " + str(second))
           38         print("Abs. difference: " + str(second-first))
           39         print("Rel. difference: " + str(abs((first-second)/first)))
           40         raise Exception("Failed")
           41         return(1)
           42 
           43 def compareNumpyArrays(first, second, string):
           44     if ((first == second).all()):
           45         print(string + passed())
           46     else :
           47         print(string + failed())
           48         raise Exception("Failed")
           49         return(1)
           50 
           51 def compareNumpyArraysClose(first, second, string, tolerance=1e-5):
           52     if (numpy.allclose(first, second, atol=tolerance)):
           53         print(string + passed())
           54     else :
           55         print(string + failed())
           56         print(numpy.min(first))
           57         print(numpy.mean(first))
           58         print(numpy.max(first))
           59         print(numpy.min(second))
           60         print(numpy.mean(second))
           61         print(numpy.max(second))
           62         raise Exception("Failed")
           63         return(1)