Guest User

Untitled

a guest
Jan 19th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.45 KB | None | 0 0
  1. #pragma once
  2.  
  3. int replace2 (double *pb, double *pb1, double *pe, bool (*predicat)(double i, double j));
  4.  
  5.  
  6. // Replace2.cpp: определяет точку входа для консольного приложения.
  7. //
  8.  
  9.  
  10. #include <cstdio>
  11. #include <cstdlib>
  12.  
  13.  
  14.  
  15. int replace2 (double *pb, double *pb1, double *pe, bool (*predicat)(double i, double j))
  16. {
  17.     int count = 0;
  18.     for (double *i = pb, *j = pb1 ; i != pe; ++i,++j){
  19.         if(predicat(*i, *j)) {
  20.             *i = *j;
  21.             ++count;
  22.         }
  23.     }
  24.     return count;
  25.  
  26.      
  27. }
  28.  
  29.  
  30.  
  31. #include<random>
  32. #include <functional>
  33. #include <ctime>
  34. #include <cmath>
  35.  
  36. #include "gtest/gtest.h"
  37. #include "Replace2.h"
  38.  
  39. using namespace std;
  40.  
  41. mt19937 generator(time(0)); //Or just "mt19937 generator;" for repeated sequence. Try it!
  42. uniform_real_distribution<double> unif_real_01(0.0, 1.0);
  43. auto genAlpha = bind(unif_real_01, generator);
  44.  
  45. bool predicat1(double i, double j){
  46.         if (i == j) return true;
  47.         else return false;
  48. }
  49.  
  50. bool predicat2(double i, double j){
  51.         if (i ==(j) + 1) return true;
  52.         else return false;
  53. }
  54.  
  55. bool predicat3(double i, double j){
  56.         if (i == (j) * 2) return true;
  57.         else return false;
  58. }
  59.  
  60.  
  61. TEST(Test_predicat1, with_equal_numbers) {
  62.     const int N = 5;
  63.     double a[N] = {5, 0, -7, 0, 100};
  64.     double b[N] = {5, 0, -7, 0, 100};
  65.     ASSERT_EQ((replace2(a, b, a + N, predicat1)), N);
  66. }
  67.  
  68.  
  69. GTEST_API_ int main(int argc, char **argv) {
  70. testing::InitGoogleTest(&argc, argv);
  71. return RUN_ALL_TESTS();
  72. }
Add Comment
Please, Sign In to add comment