parallel_set.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // ======================================================================== //
  2. // Copyright 2009-2017 Intel Corporation //
  3. // //
  4. // Licensed under the Apache License, Version 2.0 (the "License"); //
  5. // you may not use this file except in compliance with the License. //
  6. // You may obtain a copy of the License at //
  7. // //
  8. // http://www.apache.org/licenses/LICENSE-2.0 //
  9. // //
  10. // Unless required by applicable law or agreed to in writing, software //
  11. // distributed under the License is distributed on an "AS IS" BASIS, //
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
  13. // See the License for the specific language governing permissions and //
  14. // limitations under the License. //
  15. // ======================================================================== //
  16. #include "parallel_set.h"
  17. #include "../sys/regression.h"
  18. namespace embree
  19. {
  20. struct parallel_set_regression_test : public RegressionTest
  21. {
  22. parallel_set_regression_test(const char* name) : RegressionTest(name) {
  23. registerRegressionTest(this);
  24. }
  25. bool run ()
  26. {
  27. bool passed = true;
  28. /* create vector with random numbers */
  29. const size_t N = 10000;
  30. std::vector<uint32_t> unsorted(N);
  31. for (size_t i=0; i<N; i++) unsorted[i] = 2*rand();
  32. /* created set from numbers */
  33. parallel_set<uint32_t> sorted;
  34. sorted.init(unsorted);
  35. /* check that all elements are in the set */
  36. for (size_t i=0; i<N; i++) {
  37. passed &= sorted.lookup(unsorted[i]);
  38. }
  39. /* check that these elements are not in the set */
  40. for (size_t i=0; i<N; i++) {
  41. passed &= !sorted.lookup(unsorted[i]+1);
  42. }
  43. return passed;
  44. }
  45. };
  46. parallel_set_regression_test parallel_set_regression("parallel_set_regression_test");
  47. }