1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // <string> 11 12 // int compare(const basic_string& str) const 13 14 #include <string> 15 #include <cassert> 16 17 int sign(int x) 18 { 19 if (x == 0) 20 return 0; 21 if (x < 0) 22 return -1; 23 return 1; 24 } 25 26 template <class S> 27 void 28 test(const S& s, const S& str, int x) 29 { 30 assert(sign(s.compare(str)) == sign(x)); 31 } 32 33 typedef std::string S; 34 35 int main() 36 { 37 test(S(""), S(""), 0); 38 test(S(""), S("abcde"), -5); 39 test(S(""), S("abcdefghij"), -10); 40 test(S(""), S("abcdefghijklmnopqrst"), -20); 41 test(S("abcde"), S(""), 5); 42 test(S("abcde"), S("abcde"), 0); 43 test(S("abcde"), S("abcdefghij"), -5); 44 test(S("abcde"), S("abcdefghijklmnopqrst"), -15); 45 test(S("abcdefghij"), S(""), 10); 46 test(S("abcdefghij"), S("abcde"), 5); 47 test(S("abcdefghij"), S("abcdefghij"), 0); 48 test(S("abcdefghij"), S("abcdefghijklmnopqrst"), -10); 49 test(S("abcdefghijklmnopqrst"), S(""), 20); 50 test(S("abcdefghijklmnopqrst"), S("abcde"), 15); 51 test(S("abcdefghijklmnopqrst"), S("abcdefghij"), 10); 52 test(S("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrst"), 0); 53 } 54