Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- int replace2 (double *pb, double *pb1, double *pe, bool (*predicat)(double i, double j));
- // Replace2.cpp: определяет точку входа для консольного приложения.
- //
- #include <cstdio>
- #include <cstdlib>
- int replace2 (double *pb, double *pb1, double *pe, bool (*predicat)(double i, double j))
- {
- int count = 0;
- for (double *i = pb, *j = pb1 ; i != pe; ++i,++j){
- if(predicat(*i, *j)) {
- *i = *j;
- ++count;
- }
- }
- return count;
- }
- #include<random>
- #include <functional>
- #include <ctime>
- #include <cmath>
- #include "gtest/gtest.h"
- #include "Replace2.h"
- using namespace std;
- mt19937 generator(time(0)); //Or just "mt19937 generator;" for repeated sequence. Try it!
- uniform_real_distribution<double> unif_real_01(0.0, 1.0);
- auto genAlpha = bind(unif_real_01, generator);
- bool predicat1(double i, double j){
- if (i == j) return true;
- else return false;
- }
- bool predicat2(double i, double j){
- if (i ==(j) + 1) return true;
- else return false;
- }
- bool predicat3(double i, double j){
- if (i == (j) * 2) return true;
- else return false;
- }
- TEST(Test_predicat1, with_equal_numbers) {
- const int N = 5;
- double a[N] = {5, 0, -7, 0, 100};
- double b[N] = {5, 0, -7, 0, 100};
- ASSERT_EQ((replace2(a, b, a + N, predicat1)), N);
- }
- GTEST_API_ int main(int argc, char **argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
- }
Add Comment
Please, Sign In to add comment