Search
 
SCRIPT & CODE EXAMPLE
 

CPP

c++ Testing implementation details for automated assessment of sorting algorithms

struct S
{
  static std::vector<std::pair<int, int>> * comparisonLog;

  int x;

  S(int t_x) : x(t_x) { }

  bool operator <(const S & t_other) const
  {
      comparisonLog->push_back({x, t_other.x});
      
      return x < t_other.x;
  }
};

std::vector<std::pair<int, int>> * S::comparisonLog;

//test

    std::vector<std::pair<int, int>> referenceComparisons, studentComparisons;

    const std::vector<S> values = { 1, 5, 4, 3, 2 };

    S::comparisonLog = &referenceComparisons;
    {
      auto toSort = values;
      std::sort(toSort.begin(), toSort.end());
    }

    S::comparisonLog = &studentComparisons;
    {
        auto toSort = values;
        studentSort(toSort);
        assert(std::is_sorted(toSort.begin(), toSort.end()));
    }

    assert(referenceComparisons == studentComparisons);
Comment

PREVIOUS NEXT
Code Example
Cpp :: class how to call main method inheritance in c++ 
Cpp :: Types of Conversions- C++ 
Cpp :: 10^18 data type in c++ 
Cpp :: beecrowd problem 1001 solution in c++ 
Cpp :: why wont a function stop C++ 
Cpp :: default parameter c++ a field 
Cpp :: I/O Redirection in C++ 
Cpp :: c++ conditional typedef 
Cpp :: how to install open cv2 in c++ on ubuntu 
Cpp :: case 1 or 2 c++ 
Cpp :: cpp stacks 
Cpp :: c++ to mips assembly converter 
Cpp :: CPP Find options passed from command line 
Cpp :: Difference Array | Range update query in O 
Cpp :: hamming c++ 
Cpp :: c++ freecodecamp course 10 hours youtube 
Cpp :: http://nv-study.ru/http://nv-study.ru/http://nv-study.ru/ 
Cpp :: c++ thread id 
Cpp :: what is vector capacity in c++ 
Cpp :: c++ cout format specifier for correct number of decimal points 
Cpp :: how to merge string array in C++ 
Cpp :: c++ set value to inf 
Cpp :: c++ How can I make a std::vector of function pointers 
Cpp :: fibonacci search algorithm c++ 
Cpp :: pycuda install failed microsoft c++ 
Cpp :: how to run c++ on cmd 
Cpp :: 5 program code in c++ of friend function 
Cpp :: operator using 
Cpp :: c++ negate boolean 
Cpp :: sum of 2 arrays c++ 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =