1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 #include "mozilla/EnumeratedArray.h"
8
9 enum class AnimalSpecies
10 {
11 Cow,
12 Sheep,
13 Pig,
14 Count
15 };
16
TestInitialValueByConstructor()17 void TestInitialValueByConstructor()
18 {
19 using namespace mozilla;
20 // Style 1
21 EnumeratedArray<AnimalSpecies, AnimalSpecies::Count, int> headCount(1, 2, 3);
22 MOZ_RELEASE_ASSERT(headCount[AnimalSpecies::Cow] == 1);
23 MOZ_RELEASE_ASSERT(headCount[AnimalSpecies::Sheep] == 2);
24 MOZ_RELEASE_ASSERT(headCount[AnimalSpecies::Pig] == 3);
25 // Style 2
26 EnumeratedArray<AnimalSpecies, AnimalSpecies::Count, int> headCount2{5, 6, 7};
27 MOZ_RELEASE_ASSERT(headCount2[AnimalSpecies::Cow] == 5);
28 MOZ_RELEASE_ASSERT(headCount2[AnimalSpecies::Sheep] == 6);
29 MOZ_RELEASE_ASSERT(headCount2[AnimalSpecies::Pig] == 7);
30 // Style 3
31 EnumeratedArray<AnimalSpecies, AnimalSpecies::Count, int> headCount3({8, 9, 10});
32 MOZ_RELEASE_ASSERT(headCount3[AnimalSpecies::Cow] == 8);
33 MOZ_RELEASE_ASSERT(headCount3[AnimalSpecies::Sheep] == 9);
34 MOZ_RELEASE_ASSERT(headCount3[AnimalSpecies::Pig] == 10);
35 }
36
37 int
main()38 main()
39 {
40 TestInitialValueByConstructor();
41 return 0;
42 }