OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #include "Test.h" | 8 #include "Test.h" |
9 #include "SkFloatBits.h" | 9 #include "SkFloatBits.h" |
10 #include "SkFloatingPoint.h" | 10 #include "SkFloatingPoint.h" |
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 } | 684 } |
685 for (size_t i = 0; i < SK_ARRAY_COUNT(g32); ++i) { | 685 for (size_t i = 0; i < SK_ARRAY_COUNT(g32); ++i) { |
686 REPORTER_ASSERT(reporter, g32[i].fYang == SkEndianSwap32(g32[i].fYin)); | 686 REPORTER_ASSERT(reporter, g32[i].fYang == SkEndianSwap32(g32[i].fYin)); |
687 } | 687 } |
688 for (size_t i = 0; i < SK_ARRAY_COUNT(g64); ++i) { | 688 for (size_t i = 0; i < SK_ARRAY_COUNT(g64); ++i) { |
689 REPORTER_ASSERT(reporter, g64[i].fYang == SkEndianSwap64(g64[i].fYin)); | 689 REPORTER_ASSERT(reporter, g64[i].fYang == SkEndianSwap64(g64[i].fYin)); |
690 } | 690 } |
691 } | 691 } |
692 | 692 |
693 DEFINE_TESTCLASS("Endian", EndianTestClass, TestEndian) | 693 DEFINE_TESTCLASS("Endian", EndianTestClass, TestEndian) |
| 694 |
| 695 template <typename T> |
| 696 static void test_divmod(skiatest::Reporter* r) { |
| 697 const struct { |
| 698 T numer; |
| 699 T denom; |
| 700 } kEdgeCases[] = { |
| 701 {(T)17, (T)17}, |
| 702 {(T)17, (T)4}, |
| 703 {(T)0, (T)17}, |
| 704 // For unsigned T these negatives are just some large numbers. Doesn't
hurt to test them. |
| 705 {(T)-17, (T)-17}, |
| 706 {(T)-17, (T)4}, |
| 707 {(T)17, (T)-4}, |
| 708 {(T)-17, (T)-4}, |
| 709 }; |
| 710 |
| 711 for (size_t i = 0; i < SK_ARRAY_COUNT(kEdgeCases); i++) { |
| 712 const T numer = kEdgeCases[i].numer; |
| 713 const T denom = kEdgeCases[i].denom; |
| 714 T div, mod; |
| 715 SkTDivMod(numer, denom, &div, &mod); |
| 716 REPORTER_ASSERT(r, numer/denom == div); |
| 717 REPORTER_ASSERT(r, numer%denom == mod); |
| 718 } |
| 719 |
| 720 SkRandom rand; |
| 721 for (size_t i = 0; i < 10000; i++) { |
| 722 const T numer = (T)rand.nextS(); |
| 723 T denom = 0; |
| 724 while (0 == denom) { |
| 725 denom = (T)rand.nextS(); |
| 726 } |
| 727 T div, mod; |
| 728 SkTDivMod(numer, denom, &div, &mod); |
| 729 REPORTER_ASSERT(r, numer/denom == div); |
| 730 REPORTER_ASSERT(r, numer%denom == mod); |
| 731 } |
| 732 } |
| 733 |
| 734 DEF_TEST(divmod_u8, r) { |
| 735 test_divmod<uint8_t>(r); |
| 736 } |
| 737 |
| 738 DEF_TEST(divmod_u16, r) { |
| 739 test_divmod<uint16_t>(r); |
| 740 } |
| 741 |
| 742 DEF_TEST(divmod_u32, r) { |
| 743 test_divmod<uint32_t>(r); |
| 744 } |
| 745 |
| 746 DEF_TEST(divmod_u64, r) { |
| 747 test_divmod<uint64_t>(r); |
| 748 } |
| 749 |
| 750 DEF_TEST(divmod_s8, r) { |
| 751 test_divmod<int8_t>(r); |
| 752 } |
| 753 |
| 754 DEF_TEST(divmod_s16, r) { |
| 755 test_divmod<int16_t>(r); |
| 756 } |
| 757 |
| 758 DEF_TEST(divmod_s32, r) { |
| 759 test_divmod<int32_t>(r); |
| 760 } |
| 761 |
| 762 DEF_TEST(divmod_s64, r) { |
| 763 test_divmod<int64_t>(r); |
| 764 } |
OLD | NEW |