Skip to content

Instantly share code, notes, and snippets.

@lithiumhead
Created January 31, 2018 17:13

Revisions

  1. lithiumhead created this gist Jan 31, 2018.
    26 changes: 26 additions & 0 deletions 01sqrt_pass.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    #include <iostream>
    #include <math.h>
    #include <gtest/gtest.h>

    double squareroot (double a) {
    if(a<0)
    return -1;
    else
    return sqrt(a);
    };

    TEST (SquareRootTest, PositiveNos) {
    EXPECT_EQ (18.0, squareroot (324.0));
    EXPECT_EQ (25.4, squareroot (645.16));
    EXPECT_EQ (50.332, squareroot (2533.310224));
    }

    TEST (SquareRootTest, ZeroAndNegativeNos) {
    ASSERT_EQ (0.0, squareroot (0.0));
    ASSERT_EQ (-1, squareroot (-22.0));
    }

    int main(int argc, char **argv) {
    ::testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
    }