                                                       global_write_index );
     cudaDeviceSynchronize();
 
-    unsigned int result_size = *global_write_index;
+    size_t result_size = *global_write_index;
 
     // Return the actual size of the result
     return result_size;
 
   }
 
-  void verify_groupby_result(std::map<key_type, value_type> const & expected_values ) const
+  void verify_groupby_result(size_t computed_result_size, std::map<key_type, value_type> const & expected_values )
   {
 
     ASSERT_NE(nullptr, d_groupby_result);
     ASSERT_NE(nullptr, d_aggregation_result);
+
+    // The size of the result should be equal to the number of unique keys
+    const auto begin = this->d_groupby_column.begin();
+    const auto end = this->d_groupby_column.end();
+    thrust::sort(begin, end);
+    size_t unique_count = thrust::unique(begin, end) - begin;
+    EXPECT_EQ(unique_count, computed_result_size);
 
     // Prefetch groupby and aggregation result to host to improve performance
     cudaMemPrefetchAsync(d_groupby_result, input_size * sizeof(key_type), cudaCpuDeviceId);
     cudaMemPrefetchAsync(d_aggregation_result, input_size * sizeof(value_type), cudaCpuDeviceId);
-
 
     for(size_type i = 0; i < expected_values.size(); ++i)
     {

{
  const int num_keys = 1;
  const int num_values_per_key = 1<<12;
  auto input = this->create_input(num_keys, num_values_per_key, 10, 10);
  auto expected_values = this->compute_reference_solution();
  this->build_aggregation_table_device(input);
  this->verify_aggregation_table(expected_values);
  unsigned int result_size = this->extract_groupby_result_device();
  this->verify_groupby_result(expected_values);

  // The size of the result should be equal to the number of unique keys
  auto begin = this->d_groupby_column.begin();
  auto end = this->d_groupby_column.end();
  thrust::sort(begin, end);
  unsigned int unique_count = thrust::unique(begin, end) - begin;
  EXPECT_EQ(unique_count, result_size);
}

// TODO Update the create_input function to ensure all keys are actually unique

  }

  std::pair<key_type*, value_type*>
  create_input(const int num_keys, const int num_values_per_key, const int max_key = RAND_MAX, const int max_value = RAND_MAX, bool print = false, const int ratio = 1) 
  {

    input_size = num_keys * num_values_per_key;
