1/////////////////////////////////////////////////////////////////////////////// 2// 3// Copyright (c) 2015 Microsoft Corporation. All rights reserved. 4// 5// This code is licensed under the MIT License (MIT). 6// 7// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 8// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 9// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 10// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 11// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 12// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 13// THE SOFTWARE. 14// 15/////////////////////////////////////////////////////////////////////////////// 16 17#include <UnitTest++/UnitTest++.h> 18#include <gsl/gsl> 19#include <vector> 20#include <initializer_list> 21 22using namespace std; 23using namespace gsl; 24 25SUITE(at_tests) 26{ 27 TEST(static_array) 28 { 29 int a[] = { 1, 2, 3, 4 }; 30 31 for (int i = 0; i < 4; ++i) 32 CHECK(at(a, i) == i+1); 33 34 CHECK_THROW(at(a, 4), fail_fast); 35 } 36 37 TEST(std_array) 38 { 39 std::array<int,4> a = { 1, 2, 3, 4 }; 40 41 for (int i = 0; i < 4; ++i) 42 CHECK(at(a, i) == i+1); 43 44 CHECK_THROW(at(a, 4), fail_fast); 45 } 46 47 TEST(StdVector) 48 { 49 std::vector<int> a = { 1, 2, 3, 4 }; 50 51 for (int i = 0; i < 4; ++i) 52 CHECK(at(a, i) == i+1); 53 54 CHECK_THROW(at(a, 4), fail_fast); 55 } 56 57 TEST(InitializerList) 58 { 59 std::initializer_list<int> a = { 1, 2, 3, 4 }; 60 61 for (int i = 0; i < 4; ++i) 62 CHECK(at(a, i) == i+1); 63 64 CHECK_THROW(at(a, 4), fail_fast); 65 } 66} 67 68int main(int, const char *[]) 69{ 70 return UnitTest::RunAllTests(); 71} 72