Home | History | Annotate | Download | only in base
      1 // Copyright 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "base/stl_util.h"
      6 
      7 #include <set>
      8 
      9 #include "testing/gtest/include/gtest/gtest.h"
     10 
     11 namespace base {
     12 namespace {
     13 
     14 TEST(STLUtilTest, STLIsSorted) {
     15   {
     16     std::set<int> set;
     17     set.insert(24);
     18     set.insert(1);
     19     set.insert(12);
     20     EXPECT_TRUE(STLIsSorted(set));
     21   }
     22 
     23   {
     24     std::vector<int> vector;
     25     vector.push_back(1);
     26     vector.push_back(1);
     27     vector.push_back(4);
     28     vector.push_back(64);
     29     vector.push_back(12432);
     30     EXPECT_TRUE(STLIsSorted(vector));
     31     vector.back() = 1;
     32     EXPECT_FALSE(STLIsSorted(vector));
     33   }
     34 }
     35 
     36 TEST(STLUtilTest, STLSetDifference) {
     37   std::set<int> a1;
     38   a1.insert(1);
     39   a1.insert(2);
     40   a1.insert(3);
     41   a1.insert(4);
     42 
     43   std::set<int> a2;
     44   a2.insert(3);
     45   a2.insert(4);
     46   a2.insert(5);
     47   a2.insert(6);
     48   a2.insert(7);
     49 
     50   {
     51     std::set<int> difference;
     52     difference.insert(1);
     53     difference.insert(2);
     54     EXPECT_EQ(difference, STLSetDifference<std::set<int> >(a1, a2));
     55   }
     56 
     57   {
     58     std::set<int> difference;
     59     difference.insert(5);
     60     difference.insert(6);
     61     difference.insert(7);
     62     EXPECT_EQ(difference, STLSetDifference<std::set<int> >(a2, a1));
     63   }
     64 
     65   {
     66     std::vector<int> difference;
     67     difference.push_back(1);
     68     difference.push_back(2);
     69     EXPECT_EQ(difference, STLSetDifference<std::vector<int> >(a1, a2));
     70   }
     71 
     72   {
     73     std::vector<int> difference;
     74     difference.push_back(5);
     75     difference.push_back(6);
     76     difference.push_back(7);
     77     EXPECT_EQ(difference, STLSetDifference<std::vector<int> >(a2, a1));
     78   }
     79 }
     80 
     81 }  // namespace
     82 }  // namespace base
     83