TEST(MatStatTest, Can_Fold_Up_Dispersions) { // Arrange vector<double> sample_1{ 1.0, 3.0, 4.0, -1.0, 0.0 }; vector<double> sample_2{ 5.0, 3.0, -1.0, -5.0, 4.0 }; vector<double> probabilities_1{ 0.2, 0.1, 0.3333, 0.1, 0.2667 }; vector<double> probabilities_2{ 0.1, 0.2, 0.2667, 0.1, 0.3333 }; Sample S_1(sample_1, probabilities_1); Sample S_2(sample_2, probabilities_2); // Act double math_expect_1 = S_1.CalcMathematicalExpectation(); double math_expect_2 = S_2.CalcMathematicalExpectation(); double el_moment_two_exp_1 = S_1.CalcElementaryMoment(2); double el_moment_two_exp_2 = S_2.CalcElementaryMoment(2); double dispersion_of_sum_two_rand_vals = 0.0; double dispersion_S_1 = S_1.CalcDispersion(); double dispersion_S_2 = S_2.CalcDispersion(); dispersion_of_sum_two_rand_vals = el_moment_two_exp_1 + 2.0 * math_expect_1 * math_expect_2 + el_moment_two_exp_2 - pow(math_expect_1, 2) - 2.0 * math_expect_1 * math_expect_2 - pow(math_expect_2, 2); // Assert EXPECT_NEAR(dispersion_S_1 + dispersion_S_2, dispersion_of_sum_two_rand_vals, SAMPLE_EPSILON); }
TEST(MatStatTest, Can_Out_Constant_From_Math_Expectation) { // Arrange double a = 2.0; vector<double> sample_1{ a * 1.0, a * 3.0, a * 4.0, a * (-1.0), a * 0.0 }; vector<double> sample_2{ 1.0, 3.0, 4.0, -1.0, 0.0 }; vector<double> probabilities{ 0.2, 0.1, 0.3333, 0.1, 0.2667 }; Sample S_1(sample_1, probabilities); Sample S_2(sample_2, probabilities); // Act // M(a * E) = a * M(E) double math_expect_1 = S_1.CalcMathematicalExpectation(); double math_expect_2 = S_2.CalcMathematicalExpectation(); // Assert EXPECT_NEAR(math_expect_1, a * math_expect_2, SAMPLE_EPSILON); }
TEST(MatStatTest, Can_Out_Constant_From_Dispersion) { // Arrange double a = 2.0; double b = 50.5; vector<double> sample_1{ a * 1.0 + b, a * 3.0 + b, a * 4.0 + b, a * (-1.0) + b, a * 0.0 + b }; vector<double> sample_2 { 1.0, 3.0, 4.0, -1.0, 0.0 }; vector<double> probabilities { 0.2, 0.1, 0.3333, 0.1, 0.2667 }; Sample S_1(sample_1, probabilities); Sample S_2(sample_2, probabilities); // Act // D(a * E + b) = a^2 * D(E) double dispersion_1 = S_1.CalcDispersion(); double dispersion_2 = S_2.CalcDispersion(); // Assert EXPECT_NEAR(dispersion_1, pow(a, 2) * dispersion_2, SAMPLE_EPSILON); }
void sweepDebugDumpBoard(sweep_board_t board, FILE *dest) { fprintf(dest, "sweep_board_t addr: %p\n", board); if(board) { fprintf(dest, "width: %u\n", board->width); fprintf(dest, "height: %u\n", board->height); fprintf(dest, "bombs: %u\n", board->bombs); fprintf(dest, "seed: %u\n", board->seed); fprintf(dest, "flags: \n"); fprintf(dest, " exploded? %s\n", B(board->exploded)); fprintf(dest, " marked? %s\n", B(board->mark)); } else { fprintf(dest, "game->board is NULL.\n"); fprintf(dest, "why would it ever be NULL?\n"); return; } fprintf(dest, "\n"); fprintf(dest, "dumping raw board: \n"); unsigned x, y; for(y=0; y<board->height; y++) { for(x=0; x<board->width; x++) { sweep_cell_t c = board->map[y*board->width+x]; if(S_2(c) > sizeof(flags)) { // Sanity check 2nd nybble fprintf(dest, "\nillegal flag %x at (%u, %u).\n", S_20(c), x, y); } else { fprintf(dest, "%c", flags[S_2(c)]); } if(S_1(c) > sizeof(tiles)) { fprintf(dest, "\nillegal tile %x at (%u, %u).\n", S_1(c), x, y); } else { fprintf(dest, "%c ", tiles[S_1(c)]); } } fprintf(dest, "\n"); } }
TEST(MatStatTest, Samples_With_Differ_Prob_Are_Inequal) { // Arrange vector<double> sample_1{ 1.0, 3.0, 4.0, -1.0, 0.0 }; vector<double> probabilities_1{ 0.2, 0.1, 0.3333, 0.1, 0.2667 }; vector<double> sample_2 { 1.0, 3.0, 4.0, -1.0, 0.0 }; vector<double> probabilities_2 { 0.2, 0.1, 0.2667, 0.1, 0.3333 }; Sample S_1(sample_1, probabilities_1); Sample S_2(sample_2, probabilities_2); // Act & Assert ASSERT_FALSE(S_1 == S_2); }
TEST(MatStatTest, Can_Assign_Sample_With_Other_Size) { // Arrange vector<double> sample_1 { 1.0, 3.0, 4.0, -1.0, 0.0 }; vector<double> probabilities_1 { 0.2, 0.1, 0.3333, 0.1, 0.2667 }; vector<double> sample_2 { 1.0, 3.0, 4.0, -1.0 }; vector<double> probabilities_2 { 0.2, 0.1, 0.3333, 0.3667 }; Sample S_1(sample_1, probabilities_1); Sample S_2(sample_2, probabilities_2); // Act S_2 = S_1; // Assert ASSERT_EQ(S_1, S_2); }
sweep_linear_t sweepBoardCellLinearize(sweep_cell_t c){ if(S_20(c) == SWEEP_OPEN) return S_1(c); return SWEEP_L_CLOSED + S_2(c) - 1; }