def test_first_matrix_fetched_correctly(self):
     """ Test for a drawlog of a 2d celldevs for only 1 drawing with only 0's in the matrix"""
     drawlog_path = simplestDrawlogPath()
     file_parser = CDevsFileParser(drawlog_path)
     matrices = file_parser.onlyMatrices()
     first_matrix_lines = next(matrices).splitlines()
     correct_lines = simplestMatrixStr().splitlines()
     for res,correct in zip(first_matrix_lines,correct_lines):
         self.assertEqual(res,correct)
 def test_first_and_matrix_fetched_correctly(self):
     """ Test for a drawlog of a 2d celldevs for 2 times """
     drawlog_path = twoTimesDrawlogPath()
     first_matrix = twoTimesDrwFirstMatrix()
     second_matrix = twoTimesDrwSecondMatrix()
     file_parser = CDevsFileParser(drawlog_path)
     matrices = file_parser.onlyMatrices()
     first_matrix_lines = next(matrices).splitlines()
     first_matrix_correct_lines = twoTimesDrwFirstMatrix().splitlines()
     for res,correct in zip(first_matrix_lines,first_matrix_correct_lines):
         self.assertEqual(res,correct)
     second_matrix_lines = next(matrices).splitlines()
     second_matrix_correct_lines = twoTimesDrwSecondMatrix().splitlines()
     for res,correct in zip(second_matrix_lines,second_matrix_correct_lines):
         self.assertEqual(res,correct)
def main(**kwargs):
    #Prints
    print("Running with:")
    for key, value in kwargs.items():
        print(key, value)

    file_parser = CDevsFileParser(kwargs["infile"])

    matrix_and_time_and_lineno_gen = file_parser.matrixAndTimeAndLineTuple()
    rows = [["Time","Line","Sum","Min","Max","Mean"]]
    for matrix_str,time,lineno in matrix_and_time_and_lineno_gen:
        cdevs_matrix =  CDevsMatrix(matrix_str,kwargs["col_width"])
        matrix_sum = cdevs_matrix.sum()
        matrix_min = cdevs_matrix.min()
        matrix_max = cdevs_matrix.max()
        matrix_mean = cdevs_matrix.mean()
        if(invalidMatrixMeanFromMinAndMax(matrix_mean,matrix_min,matrix_max)):
            raise Exception("Matrix mean: " + str(matrix_mean) + " is smaller than the min: "  +
                    str(matrix_min) + " or larger than the max: " + str(matrix_max))
        rows.append([time,lineno,matrix_sum,matrix_min,matrix_max,matrix_mean])
    writeRowsAsCSV(rows,kwargs["out"])