FIRVectorValueTests.mm 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright 2024 Google LLC
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <FirebaseFirestore/FIRFieldValue.h>
  17. #import <FirebaseFirestore/FIRVectorValue.h>
  18. #import <XCTest/XCTest.h>
  19. NS_ASSUME_NONNULL_BEGIN
  20. @interface FIRVectorValueTests : XCTestCase
  21. @end
  22. @implementation FIRVectorValueTests
  23. - (void)testCreateAndReadVectorValue {
  24. FIRVectorValue *vector = [FIRFieldValue vectorWithArray:@[
  25. @DBL_MIN, @0.0, [NSNumber numberWithLong:((long)pow(2, 53)) + 1], @DBL_MAX, @DBL_EPSILON,
  26. @INT64_MAX
  27. ]];
  28. NSArray<NSNumber *> *outArray = vector.array;
  29. XCTAssertEqualObjects([outArray objectAtIndex:0], @DBL_MIN);
  30. XCTAssertEqualObjects([outArray objectAtIndex:1], @0.0);
  31. // Assert that if the vector is created with large long values,
  32. // then the data will be truncated as a double.
  33. XCTAssertEqual([outArray objectAtIndex:2].longValue, pow(2, 53));
  34. XCTAssertEqualObjects([outArray objectAtIndex:3], @DBL_MAX);
  35. XCTAssertEqualObjects([outArray objectAtIndex:4], @DBL_EPSILON);
  36. XCTAssertEqualObjects([outArray objectAtIndex:5], @INT64_MAX);
  37. }
  38. @end
  39. NS_ASSUME_NONNULL_END