public void TestGetPercentPassed() { foreach (DbConnection connection in populousConnections) { // For now, throw if pull request not found. if (connection is SQLiteConnection) { Assert.Throws <Exception>(() => DBFunctions.GetPercentPassed(connection, 0)); } else { Assert.Throws <System.Data.SqlClient.SqlException>(() => DBFunctions.GetPercentPassed(connection, 0)); } // 0 out of 1 tables passed the tests. Assert.AreEqual(0, DBFunctions.GetPercentPassed(connection, 1)); // Add 2 more P/O tables, both of which passed the tests. DataTable poDetails = TableFactory.CreateEmptyPredictedObservedDetailsTable(); poDetails.Rows.Add(1, "DailyPredictedObserved", "Report", "DailyObs", "xval2", null, null, 100, 1, null); poDetails.Rows.Add(1, "DailyPredictedObserved", "Report", "DailyObs", "xval2", null, null, 100, 1, null); Utility.InsertDataIntoDatabase(connection, poDetails); // 2 out of 3 tables passed the tests. Assert.AreEqual(66, DBFunctions.GetPercentPassed(connection, 1)); // Delete the failed table (if only it were this easy irl). using (DbCommand command = connection.CreateCommand("DELETE FROM PredictedObservedDetails WHERE PassedTests = 0;")) command.ExecuteNonQuery(); // 2 out of 2 tables passed the tests. Assert.AreEqual(100, DBFunctions.GetPercentPassed(connection, 1)); } }
public void TestGetFileCount() { foreach (DbConnection connection in emptyConnections) { // todo: why is this 0? Assert.AreEqual(0, DBFunctions.GetFileCount(connection, 1)); } foreach (DbConnection connection in populousConnections) { Assert.AreEqual(0, DBFunctions.GetFileCount(connection, 0)); Assert.AreEqual(1, DBFunctions.GetFileCount(connection, 1)); // Add 3 more apsim files. DataTable apsimFiles = TableFactory.CreateEmptyApsimFilesTable(); apsimFiles.Rows.Add(1, "wheat.apsimx", "~/wheat.apsimx", new DateTime(2020, 1, 1), 0, 1, "submitdetails", -1, null); apsimFiles.Rows.Add(1, "wheat.apsimx", "~/wheat.apsimx", new DateTime(2020, 1, 1), 0, 1, "submitdetails", -1, null); apsimFiles.Rows.Add(1, "wheat.apsimx", "~/wheat.apsimx", new DateTime(2020, 1, 1), 0, 1, "submitdetails", -1, null); Utility.InsertDataIntoDatabase(connection, apsimFiles); // At this point, we haven't added any P/O details for these files, // so the file count should still be 1. Assert.AreEqual(1, DBFunctions.GetFileCount(connection, 1)); DataTable poDetails = TableFactory.CreateEmptyPredictedObservedDetailsTable(); poDetails.Rows.Add(1, "PredictedObserved", "HarvestReport", "Observations", "xval", null, null, 0, 1, null); poDetails.Rows.Add(1, "PredictedObserved", "HarvestReport", "Observations", "xval", null, null, 0, 1, null); poDetails.Rows.Add(1, "PredictedObserved", "HarvestReport", "Observations", "xval", null, null, 0, 1, null); Utility.InsertDataIntoDatabase(connection, poDetails); Assert.AreEqual(0, DBFunctions.GetFileCount(connection, 0)); Assert.AreEqual(4, DBFunctions.GetFileCount(connection, 1)); } }
private static void Populate(DbConnection connection) { DataTable simulations = TableFactory.CreateEmptySimulationsTable(); simulations.Rows.Add(1, "sim1", 1); simulations.Rows.Add(1, "sim2", 2); InsertDataIntoDatabase(connection, simulations); DataTable apsimFiles = TableFactory.CreateEmptyApsimFilesTable(); apsimFiles.Rows.Add(1, "wheat.apsimx", "~/wheat.apsimx", new DateTime(2020, 1, 1), 0, 1, "submitdetails", -1, null); InsertDataIntoDatabase(connection, apsimFiles); DataTable poDetails = TableFactory.CreateEmptyPredictedObservedDetailsTable(); poDetails.Rows.Add(1, "PredictedObserved", "HarvestReport", "Observations", "xval", null, null, 0, 1, null); InsertDataIntoDatabase(connection, poDetails); DataTable poValues = TableFactory.CreateEmptyPredictedObservedValuesTable(); poValues.Rows.Add(1, 1, "xval", 0.1, null, null, null, null, "GrainWt", 0.9, 1.1); poValues.Rows.Add(1, 2, "xval", 0.1, null, null, null, null, "GrainWt", 0.5, 1.0); InsertDataIntoDatabase(connection, poValues); DataTable poTests = TableFactory.CreateEmptyPredictedObservedTestsTable(); poTests.Rows.Add(1, "GrainWt", "n", null, 2, null, 0, null, null, 0, null); poTests.Rows.Add(1, "GrainWt", "Slope", null, 4, null, 0, null, null, 1, null); poTests.Rows.Add(1, "GrainWt", "Intercept", null, -3.5, null, 0, null, null, 1, null); poTests.Rows.Add(1, "GrainWt", "SEslope", null, 0, null, 0, null, null, 1, null); poTests.Rows.Add(1, "GrainWt", "SEintercept", null, 0, null, 0, null, null, 1, null); poTests.Rows.Add(1, "GrainWt", "R2", null, 1, null, 0, null, null, 1, null); poTests.Rows.Add(1, "GrainWt", "RMSE", null, 0.380789, null, 0, null, null, 1, null); poTests.Rows.Add(1, "GrainWt", "NSE", null, -57, null, 0, null, null, 1, null); poTests.Rows.Add(1, "GrainWt", "ME", null, -0.35, null, 0, null, null, 1, null); poTests.Rows.Add(1, "GrainWt", "MAE", null, 0.35, null, 0, null, null, 1, null); poTests.Rows.Add(1, "GrainWt", "RSR", null, 5.385165, null, 0, null, null, 1, null); InsertDataIntoDatabase(connection, poTests); }