URI:
       pytestutils.py - sphere - GPU-based 3D discrete element method algorithm with optional fluid coupling
  HTML git clone git://src.adamsgaard.dk/sphere
   DIR Log
   DIR Files
   DIR Refs
   DIR LICENSE
       ---
       pytestutils.py (1764B)
       ---
            1 #!/usr/bin/env python
            2 
            3 from sphere import *
            4 from highlighttext import highlight
            5 import numpy
            6 import subprocess
            7 import sys
            8 
            9 def passed():
           10     return "\t" + highlight("Passed", "green")
           11 
           12 def failed():
           13     return "\t" + highlight("Failed", "red", True)
           14 
           15 def test(statement, string):
           16     if (statement == True):
           17         print(string + passed())
           18     else:
           19         print(string + failed())
           20         raise Exception("Failed")
           21 
           22 def compare(first, second, string):
           23     returnvalue = (first == second)
           24     if (returnvalue == True or returnvalue > 0):
           25         print(string + passed())
           26     else:
           27         print(string + failed() + ' (' + str(returnvalue) + ')')
           28         raise Exception("Failed")
           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 
           42 def compareNumpyArrays(first, second, string):
           43     if ((first == second).all()):
           44         print(string + passed())
           45     else :
           46         print(string + failed())
           47         raise Exception("Failed")
           48 
           49 def compareNumpyArraysClose(first, second, string, tolerance=1e-5):
           50     if (numpy.allclose(first, second, atol=tolerance)):
           51         print(string + passed())
           52     else :
           53         print(string + failed())
           54         print(numpy.min(first))
           55         print(numpy.mean(first))
           56         print(numpy.max(first))
           57         print(numpy.min(second))
           58         print(numpy.mean(second))
           59         print(numpy.max(second))
           60         raise Exception("Failed")