"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "googletest/samples/prime_tables.h" between
googletest-release-1.10.0.tar.gz and googletest-release-1.11.0.tar.gz

About: GoogleTest is Google's (unit) testing and mocking framework for C++ tests.

prime_tables.h  (googletest-release-1.10.0):prime_tables.h  (googletest-release-1.11.0)
skipping to change at line 34 skipping to change at line 34
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// This provides interface PrimeTable that determines whether a number is a // This provides interface PrimeTable that determines whether a number is a
// prime and determines a next prime number. This interface is used // prime and determines a next prime number. This interface is used
// in Google Test samples demonstrating use of parameterized tests. // in Google Test samples demonstrating use of parameterized tests.
#ifndef GTEST_SAMPLES_PRIME_TABLES_H_ #ifndef GOOGLETEST_SAMPLES_PRIME_TABLES_H_
#define GTEST_SAMPLES_PRIME_TABLES_H_ #define GOOGLETEST_SAMPLES_PRIME_TABLES_H_
#include <algorithm> #include <algorithm>
// The prime table interface. // The prime table interface.
class PrimeTable { class PrimeTable {
public: public:
virtual ~PrimeTable() {} virtual ~PrimeTable() {}
// Returns true if and only if n is a prime number. // Returns true if and only if n is a prime number.
virtual bool IsPrime(int n) const = 0; virtual bool IsPrime(int n) const = 0;
skipping to change at line 67 skipping to change at line 67
for (int i = 2; i*i <= n; i++) { for (int i = 2; i*i <= n; i++) {
// n is divisible by an integer other than 1 and itself. // n is divisible by an integer other than 1 and itself.
if ((n % i) == 0) return false; if ((n % i) == 0) return false;
} }
return true; return true;
} }
int GetNextPrime(int p) const override { int GetNextPrime(int p) const override {
for (int n = p + 1; n > 0; n++) { if (p < 0) return -1;
for (int n = p + 1;; n++) {
if (IsPrime(n)) return n; if (IsPrime(n)) return n;
} }
return -1;
} }
}; };
// Implementation #2 pre-calculates the primes and stores the result // Implementation #2 pre-calculates the primes and stores the result
// in an array. // in an array.
class PreCalculatedPrimeTable : public PrimeTable { class PreCalculatedPrimeTable : public PrimeTable {
public: public:
// 'max' specifies the maximum number the prime table holds. // 'max' specifies the maximum number the prime table holds.
explicit PreCalculatedPrimeTable(int max) explicit PreCalculatedPrimeTable(int max)
: is_prime_size_(max + 1), is_prime_(new bool[max + 1]) { : is_prime_size_(max + 1), is_prime_(new bool[max + 1]) {
skipping to change at line 124 skipping to change at line 124
} }
} }
const int is_prime_size_; const int is_prime_size_;
bool* const is_prime_; bool* const is_prime_;
// Disables compiler warning "assignment operator could not be generated." // Disables compiler warning "assignment operator could not be generated."
void operator=(const PreCalculatedPrimeTable& rhs); void operator=(const PreCalculatedPrimeTable& rhs);
}; };
#endif // GTEST_SAMPLES_PRIME_TABLES_H_ #endif // GOOGLETEST_SAMPLES_PRIME_TABLES_H_
 End of changes. 4 change blocks. 
5 lines changed or deleted 5 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)