How to use float method of test.Open class

Best Mockito-kotlin code snippet using test.Open.float

CameraToOpenGlHelperTest.kt

Source:CameraToOpenGlHelperTest.kt Github

copy

Full Screen

1/*2 * Copyright (C) 2021 Alberto Irurueta Carro (alberto@irurueta.com)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 at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * 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 and14 * limitations under the License.15 */16package com.irurueta.android.glutils17import com.irurueta.algebra.Matrix18import com.irurueta.geometry.*19import com.irurueta.statistics.UniformRandomizer20import io.mockk.unmockkAll21import org.junit.After22import org.junit.Assert.*23import org.junit.Test24import org.junit.runner.RunWith25import org.robolectric.RobolectricTestRunner26@RunWith(RobolectricTestRunner::class)27class CameraToOpenGlHelperTest {28 @After29 fun afterTest() {30 unmockkAll()31 }32 @Test33 fun checkConstants() {34 assertEquals(16, CameraToOpenGlHelper.MATRIX_LENGTH)35 }36 @Test(expected = IllegalArgumentException::class)37 fun computeProjectionMatrix_whenCameraAndZeroWidth_throwsIllegalArgumentException() {38 val camera = createCamera()39 val result = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH)40 CameraToOpenGlHelper.computeProjectionMatrix(41 camera,42 0,43 HEIGHT,44 NEAR_PLANE,45 FAR_PLANE,46 result47 )48 }49 @Test(expected = IllegalArgumentException::class)50 fun computeProjectionMatrix_whenCameraAndZeroHeight_throwsIllegalArgumentException() {51 val camera = createCamera()52 val result = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH)53 CameraToOpenGlHelper.computeProjectionMatrix(54 camera,55 WIDTH,56 0,57 NEAR_PLANE,58 FAR_PLANE,59 result60 )61 }62 @Test(expected = IllegalArgumentException::class)63 fun computeProjectionMatrix_whenCameraAndWrongResultLength_throwsIllegalArgumentException() {64 val camera = createCamera()65 val result = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH + 1)66 CameraToOpenGlHelper.computeProjectionMatrix(67 camera,68 WIDTH,69 HEIGHT,70 NEAR_PLANE,71 FAR_PLANE,72 result73 )74 }75 @Test(expected = IllegalArgumentException::class)76 fun computeProjectionMatrix_whenCameraAndZeroNearPlane_throwsIllegalArgumentException() {77 val camera = createCamera()78 val result = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH)79 CameraToOpenGlHelper.computeProjectionMatrix(80 camera,81 WIDTH,82 HEIGHT,83 0.0f,84 FAR_PLANE,85 result86 )87 }88 @Test(expected = IllegalArgumentException::class)89 fun computeProjectionMatrix_whenCameraAndSmallFarPlane_throwsIllegalArgumentException() {90 val camera = createCamera()91 val result = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH)92 CameraToOpenGlHelper.computeProjectionMatrix(93 camera,94 WIDTH,95 HEIGHT,96 NEAR_PLANE,97 NEAR_PLANE,98 result99 )100 }101 @Test102 fun computeProjectionMatrix_whenCameraAndValid_computesExpectedValue() {103 val camera1 = createCamera()104 camera1.fixCameraSign()105 camera1.normalize()106 val result = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH)107 CameraToOpenGlHelper.computeProjectionMatrix(108 camera1,109 WIDTH,110 HEIGHT,111 NEAR_PLANE,112 FAR_PLANE,113 result114 )115 val modelViewMatrix = CameraToOpenGlHelper.computeModelViewMatrixAndReturnNew(camera1)116 val camera2 = OpenGlToCameraHelper.computePinholeCameraAndReturnNew(117 result,118 modelViewMatrix,119 WIDTH,120 HEIGHT121 )122 camera2.fixCameraSign()123 camera2.normalize()124 camera2.decompose()125 assertTrue(camera1.internalMatrix.equals(camera2.internalMatrix, LARGE_ABSOLUTE_ERROR))126 }127 @Test(expected = IllegalArgumentException::class)128 fun computeProjectionMatrix_whenIntrinsicsAndZeroWidth_throwsIllegalArgumentException() {129 val intrinsicParameters = createIntrinsicParameters()130 val result = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH)131 CameraToOpenGlHelper.computeProjectionMatrix(132 intrinsicParameters,133 0,134 HEIGHT,135 NEAR_PLANE,136 FAR_PLANE,137 result138 )139 }140 @Test(expected = IllegalArgumentException::class)141 fun computeProjectionMatrix_whenIntrinsicsAndZeroHeight_throwsIllegalArgumentException() {142 val intrinsicParameters = createIntrinsicParameters()143 val result = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH)144 CameraToOpenGlHelper.computeProjectionMatrix(145 intrinsicParameters,146 WIDTH,147 0,148 NEAR_PLANE,149 FAR_PLANE,150 result151 )152 }153 @Test(expected = IllegalArgumentException::class)154 fun computeProjectionMatrix_whenIntrinsicsAndWrongResultLength_throwsIllegalArgumentException() {155 val intrinsicParameters = createIntrinsicParameters()156 val result = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH + 1)157 CameraToOpenGlHelper.computeProjectionMatrix(158 intrinsicParameters,159 WIDTH,160 HEIGHT,161 NEAR_PLANE,162 FAR_PLANE,163 result164 )165 }166 @Test(expected = IllegalArgumentException::class)167 fun computeProjectionMatrix_whenIntrinsicsAndZeroNearPlane_throwsIllegalArgumentException() {168 val intrinsicParameters = createIntrinsicParameters()169 val result = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH)170 CameraToOpenGlHelper.computeProjectionMatrix(171 intrinsicParameters,172 WIDTH,173 HEIGHT,174 0.0f,175 FAR_PLANE,176 result177 )178 }179 @Test(expected = IllegalArgumentException::class)180 fun computeProjectionMatrix_whenIntrinsicsAndSmallFarPlane_throwsIllegalArgumentException() {181 val intrinsicParameters = createIntrinsicParameters()182 val result = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH)183 CameraToOpenGlHelper.computeProjectionMatrix(184 intrinsicParameters,185 WIDTH,186 HEIGHT,187 NEAR_PLANE,188 NEAR_PLANE,189 result190 )191 }192 @Test193 fun computeProjectionMatrix_whenIntrinsicsValid_computesExpectedValue() {194 val intrinsicParameters1 = createIntrinsicParameters()195 val projectionMatrix = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH)196 CameraToOpenGlHelper.computeProjectionMatrix(197 intrinsicParameters1,198 WIDTH,199 HEIGHT,200 NEAR_PLANE,201 FAR_PLANE,202 projectionMatrix203 )204 val intrinsicParameters2 = OpenGlToCameraHelper.computePinholeCameraIntrinsicsAndReturnNew(205 projectionMatrix,206 WIDTH,207 HEIGHT208 )209 assertEquals(210 intrinsicParameters1.horizontalFocalLength,211 intrinsicParameters2.horizontalFocalLength,212 ABSOLUTE_ERROR213 )214 assertEquals(215 intrinsicParameters1.verticalFocalLength,216 intrinsicParameters2.verticalFocalLength,217 ABSOLUTE_ERROR218 )219 assertEquals(220 intrinsicParameters1.horizontalPrincipalPoint,221 intrinsicParameters2.horizontalPrincipalPoint,222 ABSOLUTE_ERROR223 )224 assertEquals(225 intrinsicParameters1.verticalPrincipalPoint,226 intrinsicParameters2.verticalPrincipalPoint,227 ABSOLUTE_ERROR228 )229 assertEquals(230 intrinsicParameters1.skewness,231 intrinsicParameters2.skewness,232 ABSOLUTE_ERROR233 )234 assertTrue(235 intrinsicParameters1.internalMatrix.equals(236 intrinsicParameters2.internalMatrix,237 ABSOLUTE_ERROR238 )239 )240 }241 @Test(expected = IllegalArgumentException::class)242 fun computeProjectionMatrixAndReturnNew_whenIntrinsicsAndZeroWidth_throwsIllegalArgumentException() {243 val intrinsicParameters = createIntrinsicParameters()244 CameraToOpenGlHelper.computeProjectionMatrixAndReturnNew(245 intrinsicParameters,246 0,247 HEIGHT,248 NEAR_PLANE,249 FAR_PLANE250 )251 }252 @Test(expected = IllegalArgumentException::class)253 fun computeProjectionMatrixAndReturnNew_whenCameraAndZeroWidth_throwsIllegalArgumentException() {254 val camera = createCamera()255 CameraToOpenGlHelper.computeProjectionMatrixAndReturnNew(256 camera,257 0,258 HEIGHT,259 NEAR_PLANE,260 FAR_PLANE261 )262 }263 @Test(expected = IllegalArgumentException::class)264 fun computeProjectionMatrixAndReturnNew_whenCameraAndZeroHeight_throwsIllegalArgumentException() {265 val camera = createCamera()266 CameraToOpenGlHelper.computeProjectionMatrixAndReturnNew(267 camera,268 WIDTH,269 0,270 NEAR_PLANE,271 FAR_PLANE272 )273 }274 @Test(expected = IllegalArgumentException::class)275 fun computeProjectionMatrixAndReturnNew_whenCameraAndZeroNearPlane_throwsIllegalArgumentException() {276 val camera = createCamera()277 CameraToOpenGlHelper.computeProjectionMatrixAndReturnNew(278 camera,279 WIDTH,280 HEIGHT,281 0.0f,282 FAR_PLANE283 )284 }285 @Test(expected = IllegalArgumentException::class)286 fun computeProjectionMatrixAndReturnNew_whenCameraAndSmallFarPlane_throwsIllegalArgumentException() {287 val camera = createCamera()288 CameraToOpenGlHelper.computeProjectionMatrixAndReturnNew(289 camera,290 WIDTH,291 HEIGHT,292 NEAR_PLANE,293 NEAR_PLANE294 )295 }296 @Test297 fun computeProjectionMatrixAndReturnNew_whenCamera_computesExpectedValue() {298 val camera1 = createCamera()299 camera1.fixCameraSign()300 camera1.normalize()301 val result = CameraToOpenGlHelper.computeProjectionMatrixAndReturnNew(302 camera1,303 WIDTH,304 HEIGHT,305 NEAR_PLANE,306 FAR_PLANE307 )308 val modelViewMatrix = CameraToOpenGlHelper.computeModelViewMatrixAndReturnNew(camera1)309 val camera2 = OpenGlToCameraHelper.computePinholeCameraAndReturnNew(310 result,311 modelViewMatrix,312 WIDTH,313 HEIGHT314 )315 camera2.fixCameraSign()316 camera2.normalize()317 camera2.decompose()318 assertTrue(camera1.internalMatrix.equals(camera2.internalMatrix, LARGE_ABSOLUTE_ERROR))319 }320 @Test(expected = IllegalArgumentException::class)321 fun computeProjectionMatrixAndReturnNew_whenIntrinsicsAndZeroHeight_throwsIllegalArgumentException() {322 val intrinsicParameters = createIntrinsicParameters()323 CameraToOpenGlHelper.computeProjectionMatrixAndReturnNew(324 intrinsicParameters,325 WIDTH,326 0,327 NEAR_PLANE,328 FAR_PLANE329 )330 }331 @Test(expected = IllegalArgumentException::class)332 fun computeProjectionMatrixAndReturnNew_whenIntrinsicsAndZeroNearPlane_throwsIllegalArgumentException() {333 val intrinsicParameters = createIntrinsicParameters()334 CameraToOpenGlHelper.computeProjectionMatrixAndReturnNew(335 intrinsicParameters,336 WIDTH,337 HEIGHT,338 0.0f,339 FAR_PLANE340 )341 }342 @Test(expected = IllegalArgumentException::class)343 fun computeProjectionMatrixAndReturnNew_whenIntrinsicsAndSmallFarPlane_throwsIllegalArgumentException() {344 val intrinsicParameters = createIntrinsicParameters()345 CameraToOpenGlHelper.computeProjectionMatrixAndReturnNew(346 intrinsicParameters,347 WIDTH,348 HEIGHT,349 NEAR_PLANE,350 NEAR_PLANE351 )352 }353 @Test354 fun computeProjectionMatrixAndReturnNew_whenIntrinsicsValid_computesExpectedValue() {355 val intrinsicParameters1 = createIntrinsicParameters()356 val projectionMatrix = CameraToOpenGlHelper.computeProjectionMatrixAndReturnNew(357 intrinsicParameters1,358 WIDTH,359 HEIGHT,360 NEAR_PLANE,361 FAR_PLANE362 )363 val intrinsicParameters2 = OpenGlToCameraHelper.computePinholeCameraIntrinsicsAndReturnNew(364 projectionMatrix,365 WIDTH,366 HEIGHT367 )368 assertEquals(369 intrinsicParameters1.horizontalFocalLength,370 intrinsicParameters2.horizontalFocalLength,371 ABSOLUTE_ERROR372 )373 assertEquals(374 intrinsicParameters1.verticalFocalLength,375 intrinsicParameters2.verticalFocalLength,376 ABSOLUTE_ERROR377 )378 assertEquals(379 intrinsicParameters1.horizontalPrincipalPoint,380 intrinsicParameters2.horizontalPrincipalPoint,381 ABSOLUTE_ERROR382 )383 assertEquals(384 intrinsicParameters1.verticalPrincipalPoint,385 intrinsicParameters2.verticalPrincipalPoint,386 ABSOLUTE_ERROR387 )388 assertEquals(389 intrinsicParameters1.skewness,390 intrinsicParameters2.skewness,391 ABSOLUTE_ERROR392 )393 assertTrue(394 intrinsicParameters1.internalMatrix.equals(395 intrinsicParameters2.internalMatrix,396 ABSOLUTE_ERROR397 )398 )399 }400 @Test(expected = IllegalArgumentException::class)401 fun computeModelViewMatrix_whenCameraAndWrongResultLength_throwsIllegalArgumentException() {402 val camera = createCamera()403 val result = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH + 1)404 CameraToOpenGlHelper.computeModelViewMatrix(camera, result)405 }406 @Test407 fun computeModelViewMatrix_whenCamera_computesExpectedValue() {408 val camera1 = createCamera()409 camera1.fixCameraSign()410 camera1.normalize()411 val result = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH)412 CameraToOpenGlHelper.computeModelViewMatrix(camera1, result)413 val projectionMatrix = CameraToOpenGlHelper.computeProjectionMatrixAndReturnNew(414 camera1.intrinsicParameters,415 WIDTH,416 HEIGHT,417 NEAR_PLANE,418 FAR_PLANE419 )420 val camera2 = OpenGlToCameraHelper.computePinholeCameraAndReturnNew(421 projectionMatrix,422 result,423 WIDTH,424 HEIGHT425 )426 camera2.fixCameraSign()427 camera2.normalize()428 camera2.decompose()429 assertTrue(camera1.internalMatrix.equals(camera2.internalMatrix, LARGE_ABSOLUTE_ERROR))430 }431 @Test432 fun computeModelViewMatrix_whenRotationCenter_computesExpectedValue() {433 val camera1 = createCamera()434 camera1.fixCameraSign()435 camera1.normalize()436 val rotation1 = camera1.cameraRotation437 val center1 = camera1.cameraCenter438 val result = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH)439 CameraToOpenGlHelper.computeModelViewMatrix(rotation1, center1, result)440 val projectionMatrix = CameraToOpenGlHelper.computeProjectionMatrixAndReturnNew(441 camera1.intrinsicParameters,442 WIDTH,443 HEIGHT,444 NEAR_PLANE,445 FAR_PLANE446 )447 val camera2 = OpenGlToCameraHelper.computePinholeCameraAndReturnNew(448 projectionMatrix,449 result,450 WIDTH,451 HEIGHT452 )453 camera2.fixCameraSign()454 camera2.normalize()455 camera2.decompose()456 assertTrue(camera1.internalMatrix.equals(camera2.internalMatrix, LARGE_ABSOLUTE_ERROR))457 }458 @Test(expected = IllegalArgumentException::class)459 fun computeModelViewMatrix_whenWrongRotationMatrixAndCenter1_throwsIllegalArgumentException() {460 val rotationMatrix = Matrix(1, 3)461 val center = Point3D.create()462 val result = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH)463 CameraToOpenGlHelper.computeModelViewMatrix(rotationMatrix, center, result)464 }465 @Test(expected = IllegalArgumentException::class)466 fun computeModelViewMatrix_whenWrongRotationMatrixAndCenter2_throwsIllegalArgumentException() {467 val rotationMatrix = Matrix(3, 1)468 val center = Point3D.create()469 val result = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH)470 CameraToOpenGlHelper.computeModelViewMatrix(rotationMatrix, center, result)471 }472 @Test(expected = IllegalArgumentException::class)473 fun computeModelViewMatrix_whenRotationMatrixCenterAndWrongResultLength_throwsIllegalArgumentException() {474 val camera = createCamera()475 camera.fixCameraSign()476 camera.normalize()477 val rotation = camera.cameraRotation478 val rotationMatrix = rotation.asInhomogeneousMatrix()479 val center = camera.cameraCenter480 val result = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH + 1)481 CameraToOpenGlHelper.computeModelViewMatrix(rotationMatrix, center, result)482 }483 @Test484 fun computeModelViewMatrix_whenRotationMatrixAndCenter_computesExpectedValue() {485 val camera1 = createCamera()486 camera1.fixCameraSign()487 camera1.normalize()488 val rotation1 = camera1.cameraRotation489 val rotationMatrix1 = rotation1.asInhomogeneousMatrix()490 val center = camera1.cameraCenter491 val result = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH)492 CameraToOpenGlHelper.computeModelViewMatrix(rotationMatrix1, center, result)493 val projectionMatrix = CameraToOpenGlHelper.computeProjectionMatrixAndReturnNew(494 camera1.intrinsicParameters,495 WIDTH,496 HEIGHT,497 NEAR_PLANE,498 FAR_PLANE,499 )500 val camera2 = OpenGlToCameraHelper.computePinholeCameraAndReturnNew(501 projectionMatrix,502 result,503 WIDTH,504 HEIGHT505 )506 camera2.fixCameraSign()507 camera2.normalize()508 camera2.decompose()509 assertTrue(camera1.internalMatrix.equals(camera2.internalMatrix, LARGE_ABSOLUTE_ERROR))510 }511 @Test512 fun computeModelViewMatrixAndReturnNew_whenCameraAndValidResult_computesExpectedValue() {513 val camera1 = createCamera()514 camera1.fixCameraSign()515 camera1.normalize()516 val result = CameraToOpenGlHelper.computeModelViewMatrixAndReturnNew(camera1)517 val projectionMatrix = CameraToOpenGlHelper.computeProjectionMatrixAndReturnNew(518 camera1.intrinsicParameters,519 WIDTH,520 HEIGHT,521 NEAR_PLANE,522 FAR_PLANE,523 )524 val camera2 = OpenGlToCameraHelper.computePinholeCameraAndReturnNew(525 projectionMatrix,526 result,527 WIDTH,528 HEIGHT529 )530 camera2.fixCameraSign()531 camera2.normalize()532 camera2.decompose()533 assertTrue(camera1.internalMatrix.equals(camera2.internalMatrix, LARGE_ABSOLUTE_ERROR))534 }535 @Test536 fun computeModelViewMatrixAndReturnNew_whenRotationAndCenter_computesExpectedValue() {537 val camera1 = createCamera()538 camera1.fixCameraSign()539 camera1.normalize()540 val rotation1 = camera1.cameraRotation541 val center1 = camera1.cameraCenter542 val result = CameraToOpenGlHelper.computeModelViewMatrixAndReturnNew(rotation1, center1)543 val projectionMatrix = CameraToOpenGlHelper.computeProjectionMatrixAndReturnNew(544 camera1.intrinsicParameters,545 WIDTH,546 HEIGHT,547 NEAR_PLANE,548 FAR_PLANE,549 )550 val camera2 = OpenGlToCameraHelper.computePinholeCameraAndReturnNew(551 projectionMatrix,552 result,553 WIDTH,554 HEIGHT555 )556 camera2.fixCameraSign()557 camera2.normalize()558 camera2.decompose()559 assertTrue(camera1.internalMatrix.equals(camera2.internalMatrix, LARGE_ABSOLUTE_ERROR))560 }561 @Test(expected = IllegalArgumentException::class)562 fun computeModelViewMatrixAndReturnNew_whenWrongRotationMatrixAndCenter1_throwsIllegalArgumentException() {563 val rotationMatrix = Matrix(1, 3)564 val center = Point3D.create()565 CameraToOpenGlHelper.computeModelViewMatrixAndReturnNew(rotationMatrix, center)566 }567 @Test(expected = IllegalArgumentException::class)568 fun computeModelViewMatrixAndReturnNew_whenWrongRotationMatrixAndCenter2_throwsIllegalArgumentException() {569 val rotationMatrix = Matrix(3, 1)570 val center = Point3D.create()571 CameraToOpenGlHelper.computeModelViewMatrixAndReturnNew(rotationMatrix, center)572 }573 @Test574 fun computeModelViewMatrixAndReturnNew_whenRotationMatrixAndCenter_computesExpectedValue() {575 val camera1 = createCamera()576 camera1.fixCameraSign()577 camera1.normalize()578 val rotation1 = camera1.cameraRotation579 val rotationMatrix1 = rotation1.asInhomogeneousMatrix()580 val center = camera1.cameraCenter581 val result =582 CameraToOpenGlHelper.computeModelViewMatrixAndReturnNew(rotationMatrix1, center)583 val projectionMatrix = CameraToOpenGlHelper.computeProjectionMatrixAndReturnNew(584 camera1.intrinsicParameters,585 WIDTH,586 HEIGHT,587 NEAR_PLANE,588 FAR_PLANE,589 )590 val camera2 = OpenGlToCameraHelper.computePinholeCameraAndReturnNew(591 projectionMatrix,592 result,593 WIDTH,594 HEIGHT595 )596 camera2.fixCameraSign()597 camera2.normalize()598 camera2.decompose()599 assertTrue(camera1.internalMatrix.equals(camera2.internalMatrix, LARGE_ABSOLUTE_ERROR))600 }601 @Test(expected = IllegalArgumentException::class)602 fun computeModelViewProjectionMatrix_whenProjectionMatrixWrongLength_throwsIllegalArgumentException() {603 val projectionMatrix = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH + 1)604 val modelViewMatrix = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH)605 val result = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH)606 CameraToOpenGlHelper.computeModelViewProjectionMatrix(607 projectionMatrix,608 modelViewMatrix,609 result610 )611 }612 @Test(expected = IllegalArgumentException::class)613 fun computeModelViewProjectionMatrix_whenModelViewMatrixWrongLength_throwsIllegalArgumentException() {614 val projectionMatrix = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH)615 val modelViewMatrix = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH + 1)616 val result = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH)617 CameraToOpenGlHelper.computeModelViewProjectionMatrix(618 projectionMatrix,619 modelViewMatrix,620 result621 )622 }623 @Test(expected = IllegalArgumentException::class)624 fun computeModelViewProjectionMatrix_whenResultWrongLength_throwsIllegalArgumentException() {625 val projectionMatrix = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH)626 val modelViewMatrix = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH)627 val result = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH + 1)628 CameraToOpenGlHelper.computeModelViewProjectionMatrix(629 projectionMatrix,630 modelViewMatrix,631 result632 )633 }634 @Test635 fun computeModelViewProjectionMatrix_whenValid_computesExpectedValue() {636 val camera = createCamera()637 camera.fixCameraSign()638 camera.normalize()639 val projectionMatrix = CameraToOpenGlHelper.computeProjectionMatrixAndReturnNew(640 camera,641 WIDTH,642 HEIGHT,643 NEAR_PLANE,644 FAR_PLANE645 )646 val modelViewMatrix = CameraToOpenGlHelper.computeModelViewMatrixAndReturnNew(camera)647 val result = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH)648 CameraToOpenGlHelper.computeModelViewProjectionMatrix(649 projectionMatrix,650 modelViewMatrix,651 result652 )653 val expected = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH)654 android.opengl.Matrix.multiplyMM(expected, 0, projectionMatrix, 0, modelViewMatrix, 0)655 assertArrayEquals(expected, result, 0.0f)656 }657 @Test(expected = IllegalArgumentException::class)658 fun computeModelViewProjectionMatrix_whenCameraAndZeroWidth_throwsIllegalArgumentException() {659 val camera = createCamera()660 val result = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH)661 CameraToOpenGlHelper.computeModelViewProjectionMatrix(662 camera,663 0,664 HEIGHT,665 NEAR_PLANE,666 FAR_PLANE,667 result668 )669 }670 @Test(expected = IllegalArgumentException::class)671 fun computeModelViewProjectionMatrix_whenCameraAndZeroHeight_throwsIllegalArgumentException() {672 val camera = createCamera()673 val result = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH)674 CameraToOpenGlHelper.computeModelViewProjectionMatrix(675 camera,676 WIDTH,677 0,678 NEAR_PLANE,679 FAR_PLANE,680 result681 )682 }683 @Test(expected = IllegalArgumentException::class)684 fun computeModelViewProjectionMatrix_whenCameraAndZeroNearPlane_throwsIllegalArgumentException() {685 val camera = createCamera()686 val result = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH)687 CameraToOpenGlHelper.computeModelViewProjectionMatrix(688 camera,689 WIDTH,690 HEIGHT,691 0.0f,692 FAR_PLANE,693 result694 )695 }696 @Test(expected = IllegalArgumentException::class)697 fun computeModelViewProjectionMatrix_whenCameraAndSmallFarPlane_throwsIllegalArgumentException() {698 val camera = createCamera()699 val result = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH)700 CameraToOpenGlHelper.computeModelViewProjectionMatrix(701 camera,702 WIDTH,703 HEIGHT,704 NEAR_PLANE,705 NEAR_PLANE,706 result707 )708 }709 @Test(expected = IllegalArgumentException::class)710 fun computeModelViewProjectionMatrix_whenCameraAndWrongResultLength_throwsIllegalArgumentException() {711 val camera = createCamera()712 val result = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH + 1)713 CameraToOpenGlHelper.computeModelViewProjectionMatrix(714 camera,715 WIDTH,716 HEIGHT,717 NEAR_PLANE,718 FAR_PLANE,719 result720 )721 }722 @Test723 fun computeModelViewProjectionMatrix_whenCamera_computesExpectedValue() {724 val camera = createCamera()725 camera.fixCameraSign()726 camera.normalize()727 val projectionMatrix = CameraToOpenGlHelper.computeProjectionMatrixAndReturnNew(728 camera,729 WIDTH,730 HEIGHT,731 NEAR_PLANE,732 FAR_PLANE733 )734 val modelViewMatrix = CameraToOpenGlHelper.computeModelViewMatrixAndReturnNew(camera)735 val expected = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH)736 CameraToOpenGlHelper.computeModelViewProjectionMatrix(737 projectionMatrix,738 modelViewMatrix,739 expected740 )741 val result = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH)742 CameraToOpenGlHelper.computeModelViewProjectionMatrix(743 camera,744 WIDTH,745 HEIGHT,746 NEAR_PLANE,747 FAR_PLANE,748 result749 )750 assertArrayEquals(expected, result, 0.0f)751 }752 @Test(expected = IllegalArgumentException::class)753 fun computeModelViewProjectionMatrix_whenIntrinsicsAndZeroWidth_throwsIllegalArgumentException() {754 val camera = createCamera()755 val intrinsics = camera.intrinsicParameters756 val rotation = camera.cameraRotation757 val center = camera.cameraCenter758 val result = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH)759 CameraToOpenGlHelper.computeModelViewProjectionMatrix(760 intrinsics,761 rotation,762 center,763 0,764 HEIGHT,765 NEAR_PLANE,766 FAR_PLANE,767 result768 )769 }770 @Test(expected = IllegalArgumentException::class)771 fun computeModelViewProjectionMatrix_whenIntrinsicsAndZeroHeight_throwsIllegalArgumentException() {772 val camera = createCamera()773 val intrinsics = camera.intrinsicParameters774 val rotation = camera.cameraRotation775 val center = camera.cameraCenter776 val result = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH)777 CameraToOpenGlHelper.computeModelViewProjectionMatrix(778 intrinsics,779 rotation,780 center,781 WIDTH,782 0,783 NEAR_PLANE,784 FAR_PLANE,785 result786 )787 }788 @Test(expected = IllegalArgumentException::class)789 fun computeModelViewProjectionMatrix_whenIntrinsicsAndZeroNearPlane_throwsIllegalArgumentException() {790 val camera = createCamera()791 val intrinsics = camera.intrinsicParameters792 val rotation = camera.cameraRotation793 val center = camera.cameraCenter794 val result = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH)795 CameraToOpenGlHelper.computeModelViewProjectionMatrix(796 intrinsics,797 rotation,798 center,799 WIDTH,800 HEIGHT,801 0.0f,802 FAR_PLANE,803 result804 )805 }806 @Test(expected = IllegalArgumentException::class)807 fun computeModelViewProjectionMatrix_whenIntrinsicsAndSmallFarPlane_throwsIllegalArgumentException() {808 val camera = createCamera()809 val intrinsics = camera.intrinsicParameters810 val rotation = camera.cameraRotation811 val center = camera.cameraCenter812 val result = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH)813 CameraToOpenGlHelper.computeModelViewProjectionMatrix(814 intrinsics,815 rotation,816 center,817 WIDTH,818 HEIGHT,819 NEAR_PLANE,820 NEAR_PLANE,821 result822 )823 }824 @Test(expected = IllegalArgumentException::class)825 fun computeModelViewProjectionMatrix_whenIntrinsicsAndWrongResultLength_throwsIllegalArgumentException() {826 val camera = createCamera()827 val intrinsics = camera.intrinsicParameters828 val rotation = camera.cameraRotation829 val center = camera.cameraCenter830 val result = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH + 1)831 CameraToOpenGlHelper.computeModelViewProjectionMatrix(832 intrinsics,833 rotation,834 center,835 WIDTH,836 HEIGHT,837 NEAR_PLANE,838 FAR_PLANE,839 result840 )841 }842 @Test843 fun computeModelViewProjectionMatrix_whenIntrinsics_computesExpectedValue() {844 val camera = createCamera()845 camera.fixCameraSign()846 camera.normalize()847 camera.decompose()848 val intrinsics = camera.intrinsicParameters849 val rotation = camera.cameraRotation850 val center = camera.cameraCenter851 val projectionMatrix = CameraToOpenGlHelper.computeProjectionMatrixAndReturnNew(852 camera,853 WIDTH,854 HEIGHT,855 NEAR_PLANE,856 FAR_PLANE857 )858 val modelViewMatrix = CameraToOpenGlHelper.computeModelViewMatrixAndReturnNew(camera)859 val expected = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH)860 CameraToOpenGlHelper.computeModelViewProjectionMatrix(861 projectionMatrix,862 modelViewMatrix,863 expected864 )865 val result = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH)866 CameraToOpenGlHelper.computeModelViewProjectionMatrix(867 intrinsics,868 rotation,869 center,870 WIDTH,871 HEIGHT,872 NEAR_PLANE,873 FAR_PLANE,874 result875 )876 assertArrayEquals(expected, result, 0.0f)877 }878 @Test(expected = IllegalArgumentException::class)879 fun computeModelViewProjectionMatrix_whenWrongRotationMatrix1_throwsIllegalArgumentException() {880 val camera = createCamera()881 val intrinsics = camera.intrinsicParameters882 val rotationMatrix = Matrix(1, 3)883 val center = camera.cameraCenter884 val result = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH)885 CameraToOpenGlHelper.computeModelViewProjectionMatrix(886 intrinsics,887 rotationMatrix,888 center,889 0,890 HEIGHT,891 NEAR_PLANE,892 FAR_PLANE,893 result894 )895 }896 @Test(expected = IllegalArgumentException::class)897 fun computeModelViewProjectionMatrix_whenWrongRotationMatrix2_throwsIllegalArgumentException() {898 val camera = createCamera()899 val intrinsics = camera.intrinsicParameters900 val rotationMatrix = Matrix(3, 1)901 val center = camera.cameraCenter902 val result = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH)903 CameraToOpenGlHelper.computeModelViewProjectionMatrix(904 intrinsics,905 rotationMatrix,906 center,907 0,908 HEIGHT,909 NEAR_PLANE,910 FAR_PLANE,911 result912 )913 }914 @Test(expected = IllegalArgumentException::class)915 fun computeModelViewProjectionMatrix_whenRotationMatrixAndZeroWidth_throwsIllegalArgumentException() {916 val camera = createCamera()917 camera.fixCameraSign()918 camera.normalize()919 camera.decompose()920 val intrinsics = camera.intrinsicParameters921 val rotation = camera.cameraRotation922 val rotationMatrix = rotation.asInhomogeneousMatrix()923 val center = camera.cameraCenter924 val result = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH)925 CameraToOpenGlHelper.computeModelViewProjectionMatrix(926 intrinsics,927 rotationMatrix,928 center,929 0,930 HEIGHT,931 NEAR_PLANE,932 FAR_PLANE,933 result934 )935 }936 @Test(expected = IllegalArgumentException::class)937 fun computeModelViewProjectionMatrix_whenRotationMatrixAndZeroHeight_throwsIllegalArgumentException() {938 val camera = createCamera()939 camera.fixCameraSign()940 camera.normalize()941 camera.decompose()942 val intrinsics = camera.intrinsicParameters943 val rotation = camera.cameraRotation944 val rotationMatrix = rotation.asInhomogeneousMatrix()945 val center = camera.cameraCenter946 val result = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH)947 CameraToOpenGlHelper.computeModelViewProjectionMatrix(948 intrinsics,949 rotationMatrix,950 center,951 WIDTH,952 0,953 NEAR_PLANE,954 FAR_PLANE,955 result956 )957 }958 @Test(expected = IllegalArgumentException::class)959 fun computeModelViewProjectionMatrix_whenRotationMatrixAndZeroNearPlane_throwsIllegalArgumentException() {960 val camera = createCamera()961 camera.fixCameraSign()962 camera.normalize()963 camera.decompose()964 val intrinsics = camera.intrinsicParameters965 val rotation = camera.cameraRotation966 val rotationMatrix = rotation.asInhomogeneousMatrix()967 val center = camera.cameraCenter968 val result = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH)969 CameraToOpenGlHelper.computeModelViewProjectionMatrix(970 intrinsics,971 rotationMatrix,972 center,973 WIDTH,974 HEIGHT,975 0.0f,976 FAR_PLANE,977 result978 )979 }980 @Test(expected = IllegalArgumentException::class)981 fun computeModelViewProjectionMatrix_whenRotationMatrixAndSmallFarPlane_throwsIllegalArgumentException() {982 val camera = createCamera()983 camera.fixCameraSign()984 camera.normalize()985 camera.decompose()986 val intrinsics = camera.intrinsicParameters987 val rotation = camera.cameraRotation988 val rotationMatrix = rotation.asInhomogeneousMatrix()989 val center = camera.cameraCenter990 val result = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH)991 CameraToOpenGlHelper.computeModelViewProjectionMatrix(992 intrinsics,993 rotationMatrix,994 center,995 WIDTH,996 HEIGHT,997 NEAR_PLANE,998 NEAR_PLANE,999 result1000 )1001 }1002 @Test(expected = IllegalArgumentException::class)1003 fun computeModelViewProjectionMatrix_whenRotationMatrixAndWrongResultLength_throwsIllegalArgumentException() {1004 val camera = createCamera()1005 camera.fixCameraSign()1006 camera.normalize()1007 camera.decompose()1008 val intrinsics = camera.intrinsicParameters1009 val rotation = camera.cameraRotation1010 val rotationMatrix = rotation.asInhomogeneousMatrix()1011 val center = camera.cameraCenter1012 val result = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH + 1)1013 CameraToOpenGlHelper.computeModelViewProjectionMatrix(1014 intrinsics,1015 rotationMatrix,1016 center,1017 WIDTH,1018 HEIGHT,1019 NEAR_PLANE,1020 FAR_PLANE,1021 result1022 )1023 }1024 @Test1025 fun computeModelViewProjectionMatrix_whenRotationMatrix_computesExpectedValue() {1026 val camera = createCamera()1027 camera.fixCameraSign()1028 camera.normalize()1029 camera.decompose()1030 val intrinsics = camera.intrinsicParameters1031 val rotation = camera.cameraRotation1032 val rotationMatrix = rotation.asInhomogeneousMatrix()1033 val center = camera.cameraCenter1034 val projectionMatrix = CameraToOpenGlHelper.computeProjectionMatrixAndReturnNew(1035 camera,1036 WIDTH,1037 HEIGHT,1038 NEAR_PLANE,1039 FAR_PLANE1040 )1041 val modelViewMatrix = CameraToOpenGlHelper.computeModelViewMatrixAndReturnNew(camera)1042 val expected = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH)1043 CameraToOpenGlHelper.computeModelViewProjectionMatrix(1044 projectionMatrix,1045 modelViewMatrix,1046 expected1047 )1048 val result = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH)1049 CameraToOpenGlHelper.computeModelViewProjectionMatrix(1050 intrinsics,1051 rotationMatrix,1052 center,1053 WIDTH,1054 HEIGHT,1055 NEAR_PLANE,1056 FAR_PLANE,1057 result1058 )1059 assertArrayEquals(expected, result, 0.0f)1060 }1061 @Test(expected = IllegalArgumentException::class)1062 fun computeModelViewProjectionMatrixAndReturnNew_whenProjectionMatrixWrongLength_throwsIllegalArgumentException() {1063 val projectionMatrix = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH + 1)1064 val modelViewMatrix = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH)1065 CameraToOpenGlHelper.computeModelViewProjectionMatrixAndReturnNew(1066 projectionMatrix,1067 modelViewMatrix1068 )1069 }1070 @Test(expected = IllegalArgumentException::class)1071 fun computeModelViewProjectionMatrixAndReturnNew_whenModelViewMatrixWrongLength_throwsIllegalArgumentException() {1072 val projectionMatrix = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH)1073 val modelViewMatrix = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH + 1)1074 CameraToOpenGlHelper.computeModelViewProjectionMatrixAndReturnNew(1075 projectionMatrix,1076 modelViewMatrix1077 )1078 }1079 @Test1080 fun computeModelViewProjectionMatrixAndReturnNew_whenValid_computesExpectedValue() {1081 val camera = createCamera()1082 camera.fixCameraSign()1083 camera.normalize()1084 val projectionMatrix = CameraToOpenGlHelper.computeProjectionMatrixAndReturnNew(1085 camera,1086 WIDTH,1087 HEIGHT,1088 NEAR_PLANE,1089 FAR_PLANE1090 )1091 val modelViewMatrix = CameraToOpenGlHelper.computeModelViewMatrixAndReturnNew(camera)1092 val result = CameraToOpenGlHelper.computeModelViewProjectionMatrixAndReturnNew(1093 projectionMatrix,1094 modelViewMatrix1095 )1096 val expected = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH)1097 android.opengl.Matrix.multiplyMM(expected, 0, projectionMatrix, 0, modelViewMatrix, 0)1098 assertArrayEquals(expected, result, 0.0f)1099 }1100 @Test(expected = IllegalArgumentException::class)1101 fun computeModelViewProjectionMatrixAndReturnNew_whenCameraAndZeroWidth_throwsIllegalArgumentException() {1102 val camera = createCamera()1103 CameraToOpenGlHelper.computeModelViewProjectionMatrixAndReturnNew(1104 camera,1105 0,1106 HEIGHT,1107 NEAR_PLANE,1108 FAR_PLANE1109 )1110 }1111 @Test(expected = IllegalArgumentException::class)1112 fun computeModelViewProjectionMatrixAndReturnNew_whenCameraAndZeroHeight_throwsIllegalArgumentException() {1113 val camera = createCamera()1114 CameraToOpenGlHelper.computeModelViewProjectionMatrixAndReturnNew(1115 camera,1116 WIDTH,1117 0,1118 NEAR_PLANE,1119 FAR_PLANE1120 )1121 }1122 @Test(expected = IllegalArgumentException::class)1123 fun computeModelViewProjectionMatrixAndReturnNew_whenCameraAndZeroNearPlane_throwsIllegalArgumentException() {1124 val camera = createCamera()1125 CameraToOpenGlHelper.computeModelViewProjectionMatrixAndReturnNew(1126 camera,1127 WIDTH,1128 HEIGHT,1129 0.0f,1130 FAR_PLANE1131 )1132 }1133 @Test(expected = IllegalArgumentException::class)1134 fun computeModelViewProjectionMatrixAndReturnNew_whenCameraAndSmallFarPlane_throwsIllegalArgumentException() {1135 val camera = createCamera()1136 CameraToOpenGlHelper.computeModelViewProjectionMatrixAndReturnNew(1137 camera,1138 WIDTH,1139 HEIGHT,1140 NEAR_PLANE,1141 NEAR_PLANE1142 )1143 }1144 @Test1145 fun computeModelViewProjectionMatrixAndReturnNew_whenCamera_computesExpectedValue() {1146 val camera = createCamera()1147 camera.fixCameraSign()1148 camera.normalize()1149 val projectionMatrix = CameraToOpenGlHelper.computeProjectionMatrixAndReturnNew(1150 camera,1151 WIDTH,1152 HEIGHT,1153 NEAR_PLANE,1154 FAR_PLANE1155 )1156 val modelViewMatrix = CameraToOpenGlHelper.computeModelViewMatrixAndReturnNew(camera)1157 val expected = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH)1158 CameraToOpenGlHelper.computeModelViewProjectionMatrix(1159 projectionMatrix,1160 modelViewMatrix,1161 expected1162 )1163 val result = CameraToOpenGlHelper.computeModelViewProjectionMatrixAndReturnNew(1164 camera,1165 WIDTH,1166 HEIGHT,1167 NEAR_PLANE,1168 FAR_PLANE1169 )1170 assertArrayEquals(expected, result, 0.0f)1171 }1172 @Test(expected = IllegalArgumentException::class)1173 fun computeModelViewProjectionMatrixAndReturnNew_whenIntrinsicsAndZeroWidth_throwsIllegalArgumentException() {1174 val camera = createCamera()1175 val intrinsics = camera.intrinsicParameters1176 val rotation = camera.cameraRotation1177 val center = camera.cameraCenter1178 CameraToOpenGlHelper.computeModelViewProjectionMatrixAndReturnNew(1179 intrinsics,1180 rotation,1181 center,1182 0,1183 HEIGHT,1184 NEAR_PLANE,1185 FAR_PLANE1186 )1187 }1188 @Test(expected = IllegalArgumentException::class)1189 fun computeModelViewProjectionMatrixAndReturnNew_whenIntrinsicsAndZeroHeight_throwsIllegalArgumentException() {1190 val camera = createCamera()1191 val intrinsics = camera.intrinsicParameters1192 val rotation = camera.cameraRotation1193 val center = camera.cameraCenter1194 CameraToOpenGlHelper.computeModelViewProjectionMatrixAndReturnNew(1195 intrinsics,1196 rotation,1197 center,1198 WIDTH,1199 0,1200 NEAR_PLANE,1201 FAR_PLANE1202 )1203 }1204 @Test(expected = IllegalArgumentException::class)1205 fun computeModelViewProjectionMatrixAndReturnNew_whenIntrinsicsAndZeroNearPlane_throwsIllegalArgumentException() {1206 val camera = createCamera()1207 val intrinsics = camera.intrinsicParameters1208 val rotation = camera.cameraRotation1209 val center = camera.cameraCenter1210 CameraToOpenGlHelper.computeModelViewProjectionMatrixAndReturnNew(1211 intrinsics,1212 rotation,1213 center,1214 WIDTH,1215 HEIGHT,1216 0.0f,1217 FAR_PLANE1218 )1219 }1220 @Test(expected = IllegalArgumentException::class)1221 fun computeModelViewProjectionMatrixAndReturnNew_whenIntrinsicsAndSmallFarPlane_throwsIllegalArgumentException() {1222 val camera = createCamera()1223 val intrinsics = camera.intrinsicParameters1224 val rotation = camera.cameraRotation1225 val center = camera.cameraCenter1226 CameraToOpenGlHelper.computeModelViewProjectionMatrixAndReturnNew(1227 intrinsics,1228 rotation,1229 center,1230 WIDTH,1231 HEIGHT,1232 NEAR_PLANE,1233 NEAR_PLANE1234 )1235 }1236 @Test1237 fun computeModelViewProjectionMatrixAndReturnNew_whenIntrinsics_computesExpectedValue() {1238 val camera = createCamera()1239 camera.fixCameraSign()1240 camera.normalize()1241 camera.decompose()1242 val intrinsics = camera.intrinsicParameters1243 val rotation = camera.cameraRotation1244 val center = camera.cameraCenter1245 val projectionMatrix = CameraToOpenGlHelper.computeProjectionMatrixAndReturnNew(1246 camera,1247 WIDTH,1248 HEIGHT,1249 NEAR_PLANE,1250 FAR_PLANE1251 )1252 val modelViewMatrix = CameraToOpenGlHelper.computeModelViewMatrixAndReturnNew(camera)1253 val expected = FloatArray(CameraToOpenGlHelper.MATRIX_LENGTH)1254 CameraToOpenGlHelper.computeModelViewProjectionMatrix(1255 projectionMatrix,1256 modelViewMatrix,1257 expected1258 )1259 val result = CameraToOpenGlHelper.computeModelViewProjectionMatrixAndReturnNew(1260 intrinsics,1261 rotation,1262 center,1263 WIDTH,1264 HEIGHT,1265 NEAR_PLANE,1266 FAR_PLANE1267 )1268 assertArrayEquals(expected, result, 0.0f)1269 }1270 @Test(expected = IllegalArgumentException::class)1271 fun computeModelViewProjectionMatrixAndReturnNew_whenWrongRotationMatrix1_throwsIllegalArgumentException() {1272 val camera = createCamera()1273 val intrinsics = camera.intrinsicParameters1274 val rotationMatrix = Matrix(1, 3)1275 val center = camera.cameraCenter1276 CameraToOpenGlHelper.computeModelViewProjectionMatrixAndReturnNew(1277 intrinsics,1278 rotationMatrix,1279 center,1280 0,1281 HEIGHT,1282 NEAR_PLANE,1283 FAR_PLANE1284 )1285 }1286 @Test(expected = IllegalArgumentException::class)1287 fun computeModelViewProjectionMatrixAndReturnNew_whenWrongRotationMatrix2_throwsIllegalArgumentException() {1288 val camera = createCamera()1289 val intrinsics = camera.intrinsicParameters1290 val rotationMatrix = Matrix(3, 1)1291 val center = camera.cameraCenter1292 CameraToOpenGlHelper.computeModelViewProjectionMatrixAndReturnNew(1293 intrinsics,1294 rotationMatrix,1295 center,1296 0,1297 HEIGHT,1298 NEAR_PLANE,1299 FAR_PLANE1300 )1301 }1302 @Test(expected = IllegalArgumentException::class)1303 fun computeModelViewProjectionMatrixAndReturnNew_whenRotationMatrixAndZeroWidth_throwsIllegalArgumentException() {1304 val camera = createCamera()1305 camera.fixCameraSign()1306 camera.normalize()1307 camera.decompose()1308 val intrinsics = camera.intrinsicParameters1309 val rotation = camera.cameraRotation1310 val rotationMatrix = rotation.asInhomogeneousMatrix()1311 val center = camera.cameraCenter1312 CameraToOpenGlHelper.computeModelViewProjectionMatrixAndReturnNew(1313 intrinsics,1314 rotationMatrix,1315 center,1316 0,1317 HEIGHT,1318 NEAR_PLANE,1319 FAR_PLANE1320 )1321 }1322 @Test(expected = IllegalArgumentException::class)1323 fun computeModelViewProjectionMatrixAndReturnNew_whenRotationMatrixAndZeroHeight_throwsIllegalArgumentException() {1324 val camera = createCamera()1325 camera.fixCameraSign()1326 camera.normalize()1327 camera.decompose()1328 val intrinsics = camera.intrinsicParameters1329 val rotation = camera.cameraRotation1330 val rotationMatrix = rotation.asInhomogeneousMatrix()1331 val center = camera.cameraCenter1332 CameraToOpenGlHelper.computeModelViewProjectionMatrixAndReturnNew(1333 intrinsics,1334 rotationMatrix,1335 center,1336 WIDTH,1337 0,1338 NEAR_PLANE,1339 FAR_PLANE1340 )1341 }1342 @Test(expected = IllegalArgumentException::class)1343 fun computeModelViewProjectionMatrixAndReturnNew_whenRotationMatrixAndZeroNearPlane_throwsIllegalArgumentException() {1344 val camera = createCamera()1345 camera.fixCameraSign()1346 camera.normalize()1347 camera.decompose()1348 val intrinsics = camera.intrinsicParameters1349 val rotation = camera.cameraRotation1350 val rotationMatrix = rotation.asInhomogeneousMatrix()1351 val center = camera.cameraCenter1352 CameraToOpenGlHelper.computeModelViewProjectionMatrixAndReturnNew(1353 intrinsics,1354 rotationMatrix,1355 center,1356 WIDTH,1357 HEIGHT,1358 0.0f,1359 FAR_PLANE1360 )1361 }1362 @Test(expected = IllegalArgumentException::class)1363 fun computeModelViewProjectionMatrixAndReturnNew_whenRotationMatrixAndSmallFarPlane_throwsIllegalArgumentException() {1364 val camera = createCamera()1365 camera.fixCameraSign()1366 camera.normalize()1367 camera.decompose()1368 val intrinsics = camera.intrinsicParameters1369 val rotation = camera.cameraRotation1370 val rotationMatrix = rotation.asInhomogeneousMatrix()1371 val center = camera.cameraCenter1372 CameraToOpenGlHelper.computeModelViewProjectionMatrixAndReturnNew(1373 intrinsics,1374 rotationMatrix,1375 center,1376 WIDTH,1377 HEIGHT,1378 NEAR_PLANE,1379 NEAR_PLANE1380 )1381 }1382 @Test1383 fun computeModelViewProjectionMatrixAndReturnNew_whenRotationMatrix_computesExpectedValue() {1384 val camera = createCamera()1385 camera.fixCameraSign()1386 camera.normalize()1387 camera.decompose()1388 val intrinsics = camera.intrinsicParameters1389 val rotation = camera.cameraRotation1390 val rotationMatrix = rotation.asInhomogeneousMatrix()1391 val center = camera.cameraCenter1392 val projectionMatrix = CameraToOpenGlHelper.computeProjectionMatrixAndReturnNew(1393 camera,1394 WIDTH,1395 HEIGHT,1396 NEAR_PLANE,1397 FAR_PLANE1398 )1399 val modelViewMatrix = CameraToOpenGlHelper.computeModelViewMatrixAndReturnNew(camera)1400 val expected = CameraToOpenGlHelper.computeModelViewProjectionMatrixAndReturnNew(1401 projectionMatrix,1402 modelViewMatrix1403 )1404 val result = CameraToOpenGlHelper.computeModelViewProjectionMatrixAndReturnNew(1405 intrinsics,1406 rotationMatrix,1407 center,1408 WIDTH,1409 HEIGHT,1410 NEAR_PLANE,1411 FAR_PLANE1412 )1413 assertArrayEquals(expected, result, 0.0f)1414 }1415 @Test1416 fun intrinsicParametersFromCamera_whenIntrinsicsAvailable_returnsExpectedValue() {1417 val camera = createCamera()1418 camera.fixCameraSign()1419 camera.normalize()1420 camera.decompose()1421 val expected = camera.intrinsicParameters1422 val result = CameraToOpenGlHelper.intrinsicParametersFromCamera(camera)1423 assertEquals(expected, result)1424 }1425 @Test1426 fun intrinsicParametersFromCamera_whenIntrinsicsNotAvailable_returnsExpectedValue() {1427 val camera1 = createCamera()1428 camera1.fixCameraSign()1429 camera1.normalize()1430 camera1.decompose()1431 val cameraMatrix = camera1.internalMatrix1432 val camera2 = PinholeCamera(cameraMatrix)1433 camera2.fixCameraSign()1434 camera2.normalize()1435 val expected = camera1.intrinsicParameters1436 val result = CameraToOpenGlHelper.intrinsicParametersFromCamera(camera2)1437 assertTrue(expected.internalMatrix.equals(result.internalMatrix, SMALL_ABSOLUTE_ERROR))1438 }1439 @Test1440 fun rotationFromCamera_whenRotationAvailable_returnsExpectedValue() {1441 val camera = createCamera()1442 camera.fixCameraSign()1443 camera.normalize()1444 camera.decompose()1445 val expected = camera.cameraRotation1446 val result = CameraToOpenGlHelper.rotationFromCamera(camera)1447 assertEquals(expected, result)1448 }1449 @Test1450 fun rotationFromCamera_whenRotationNotAvailable_returnsExpectedValue() {1451 val camera1 = createCamera()1452 camera1.fixCameraSign()1453 camera1.normalize()1454 camera1.decompose()1455 val cameraMatrix = camera1.internalMatrix1456 val camera2 = PinholeCamera(cameraMatrix)1457 camera2.fixCameraSign()1458 camera2.normalize()1459 val expected = camera1.cameraRotation1460 val result = CameraToOpenGlHelper.rotationFromCamera(camera2)1461 assertTrue(1462 expected.asInhomogeneousMatrix()1463 .equals(result.asInhomogeneousMatrix(), SMALL_ABSOLUTE_ERROR)1464 )1465 }1466 @Test1467 fun centerFromCamera_whenCenterAvailable_returnsExpectedValue() {1468 val camera = createCamera()1469 camera.fixCameraSign()1470 camera.normalize()1471 camera.decompose()1472 val expected = camera.cameraCenter1473 val result = CameraToOpenGlHelper.centerFromCamera(camera)1474 assertEquals(expected, result)1475 }1476 @Test1477 fun centerFromCamera_whenCenterNotAvailable_returnsExpectedValue() {1478 val camera1 = createCamera()1479 camera1.fixCameraSign()1480 camera1.normalize()1481 camera1.decompose()1482 val cameraMatrix = camera1.internalMatrix1483 val camera2 = PinholeCamera(cameraMatrix)1484 camera2.fixCameraSign()1485 camera2.normalize()1486 val expected = camera1.cameraCenter1487 val result = CameraToOpenGlHelper.centerFromCamera(camera2)1488 assertTrue(expected.equals(result, SMALL_ABSOLUTE_ERROR))1489 }1490 private companion object {1491 const val WIDTH = 4801492 const val HEIGHT = 6401493 const val MIN_FOCAL_LENGTH = 500.01494 const val MAX_FOCAL_LENGTH = 510.01495 const val MIN_SKEWNESS = -1e-31496 const val MAX_SKEWNESS = 1e-31497 const val HORIZONTAL_PRINCIPAL_POINT = 238.865509033203121498 const val VERTICAL_PRINCIPAL_POINT = 322.59725952148441499 const val MIN_ROTATION_ANGLE_DEGREES = -45.01500 const val MAX_ROTATION_ANGLE_DEGREES = 45.01501 const val MIN_POS = -50.01502 const val MAX_POS = 50.01503 const val NEAR_PLANE = 0.1f1504 const val FAR_PLANE = 100.0f1505 const val ABSOLUTE_ERROR = 1e-41506 const val LARGE_ABSOLUTE_ERROR = 5e-31507 const val SMALL_ABSOLUTE_ERROR = 1e-61508 private fun createIntrinsicParameters(): PinholeCameraIntrinsicParameters {1509 val randomizer = UniformRandomizer()1510 val horizontalFocalLength = randomizer.nextDouble(MIN_FOCAL_LENGTH, MAX_FOCAL_LENGTH)1511 val verticalFocalLength = -randomizer.nextDouble(MIN_FOCAL_LENGTH, MAX_FOCAL_LENGTH)1512 val skewness = randomizer.nextDouble(MIN_SKEWNESS, MAX_SKEWNESS)1513 return PinholeCameraIntrinsicParameters(1514 horizontalFocalLength,1515 verticalFocalLength,1516 HORIZONTAL_PRINCIPAL_POINT,1517 VERTICAL_PRINCIPAL_POINT,1518 skewness1519 )1520 }1521 private fun createRotation(): Rotation3D {1522 val randomizer = UniformRandomizer()1523 val roll = Math.toRadians(1524 randomizer.nextDouble(1525 MIN_ROTATION_ANGLE_DEGREES,1526 MAX_ROTATION_ANGLE_DEGREES1527 )1528 )1529 val pitch = Math.toRadians(1530 randomizer.nextDouble(1531 MIN_ROTATION_ANGLE_DEGREES,1532 MAX_ROTATION_ANGLE_DEGREES1533 )1534 )1535 val yaw = Math.toRadians(1536 randomizer.nextDouble(1537 MIN_ROTATION_ANGLE_DEGREES,1538 MAX_ROTATION_ANGLE_DEGREES1539 )1540 )1541 return Quaternion(roll, pitch, yaw)1542 }1543 private fun createCenter(): Point3D {1544 val randomizer = UniformRandomizer()1545 val x = randomizer.nextDouble(MIN_POS, MAX_POS)1546 val y = randomizer.nextDouble(MIN_POS, MAX_POS)1547 val z = randomizer.nextDouble(MIN_POS, MAX_POS)1548 return InhomogeneousPoint3D(x, y, z)1549 }1550 private fun createCamera(): PinholeCamera {1551 val intrinsicParameters = createIntrinsicParameters()1552 val rotation = createRotation()1553 val center = createCenter()1554 return PinholeCamera(intrinsicParameters, rotation, center)1555 }1556 }1557}...

Full Screen

Full Screen

KosonTest.kt

Source:KosonTest.kt Github

copy

Full Screen

...29 fun `object with all possible types of value`() {30 val representation = obj {31 "string" to "value"32 "double" to 7.633 "float" to 3.2f34 "long" to 34L35 "int" to 936 "char" to 'e'37 "short" to 12.toShort()38 "byte" to 0x3239 "boolean" to false40 "object" to obj { }41 "emptyArray" to arr42 "array" to arr["test"]43 "arrayFromIterable" to arr[listOf("test")]44 "null" to null45 "simple" to SimpleObject46 "custom" to CustomizedKoson47 "raw" to rawJson("{}")48 }.toString()49 assertThat(representation).isValidJSON()50 assertThat(representation).isEqualTo("""{"string":"value","double":7.6,"float":3.2,"long":34,"int":9,"char":"e","short":12,"byte":50,"boolean":false,"object":{},"emptyArray":[],"array":["test"],"arrayFromIterable":["test"],"null":null,"simple":"SimpleObject","custom":{"custom":11},"raw":{}}""")51 }52 @Test53 fun `should inline newlines in multi line strings`() {54 val representation = obj {55 "lines" to """56 line 157 line 258 line 359 """.trimIndent()60 }.toString()61 assertThat(representation).isEqualTo("""{"lines":"line 1\nline 2\nline 3"}""")62 }63 @Test64 fun `should inline newlines in strings`() {65 val representation = obj {66 "lines" to "line 1\nline 2\nline 3"67 }.toString()68 assertThat(representation).isEqualTo("""{"lines":"line 1\nline 2\nline 3"}""")69 }70 class Person(71 private val firstName: String,72 private val lastName: String,73 private val age: Int74 ) : CustomKoson {75 override fun serialize() = obj {76 "usualName" to "$firstName $lastName"77 "age" to age78 }79 }80 class Status(private val id: String, private val name: String) : CustomKoson {81 override fun serialize() = obj {82 "id" to id83 "name" to name84 }85 }86 @Test87 fun `CustomKoson should be serialized according to override`() {88 val name = "myName"89 val description = "desc"90 val status = Status("OK", "Nice")91 val representation = obj {92 "data" to obj {93 "name" to name94 "description" to description95 "status" to status96 }97 }.toString()98 assertThat(representation).isEqualTo("""{"data":{"name":"myName","description":"desc","status":{"id":"OK","name":"Nice"}}}""")99 }100 @Test101 fun `nullable CustomKoson should be serialized`() {102 val name = "myName"103 val description = "desc"104 val status: Status? = null105 val representation = obj {106 "data" to obj {107 "name" to name108 "description" to description109 "status" to status110 }111 }.toString()112 assertThat(representation).isEqualTo("""{"data":{"name":"myName","description":"desc","status":null}}""")113 }114 @Test115 fun `array with all possible types of value`() {116 val representation = arr[117 "value",118 7.6,119 3.2f,120 34L,121 9,122 'e',123 12.toShort(),124 0x32,125 false,126 obj { },127 arr,128 arr["test"],129 arr[listOf("test", "from", "iterable")],130 null,131 SimpleObject,132 CustomizedKoson,133 rawJson("{}")134 ].toString()135 assertThat(representation).isValidJSON()136 assertThat(representation)137 .isEqualTo("""["value",7.6,3.2,34,9,"e",12,50,false,{},[],["test"],["test","from","iterable"],null,"SimpleObject",{"custom":11},{}]""")138 }139 object ContainsDoubleQuotesAndBackslashes {140 override fun toString(): String = """"un\for"tuna\te""""141 }142 object ContainsDoubleQuotes {143 override fun toString(): String = """"unfor"tunate""""144 }145 object ContainsBackslashes {146 override fun toString(): String = """\unfor\tunate\"""147 }148 object ContainsNewLines {149 override fun toString(): String = """unfor150 |tunate""".trimMargin()151 }152 @Nested153 inner class EdgeCases {154 @Test155 fun `array containing this as a value should render`() {156 val array = arr[this]157 val representation = array.toString()158 assertThat(representation).isValidJSON()159 assertThat(representation).startsWith("[")160 assertThat(representation).endsWith("]")161 }162 @Test163 fun `object with null as key should render`() {164 val obj = obj {165 null to "content"166 }167 val representation = obj.toString()168 assertThat(representation).isValidJSON()169 assertThat(representation).isEqualTo("{}")170 }171 @Test172 fun `object with value containing backslash char`() {173 val obj = obj {174 "content" to "va\\lue"175 }176 val representation = obj.toString()177 assertThat(representation).isValidJSON()178 assertThat(representation).isEqualTo("""{"content":"va\\lue"}""")179 }180 @Test181 fun `object with custom value containing backslash char`() {182 val obj = obj {183 "content" to ContainsBackslashes184 }185 val representation = obj.toString()186 assertThat(representation).isValidJSON()187 assertThat(representation).isEqualTo("""{"content":"\\unfor\\tunate\\"}""")188 }189 @Test190 fun `object with value containing doublequotes char`() {191 val obj = obj {192 "content" to "va\"lue"193 }194 val representation = obj.toString()195 assertThat(representation).isValidJSON()196 assertThat(representation).isEqualTo("""{"content":"va\"lue"}""")197 }198 @Test199 fun `object with custom value containing doublequotes char`() {200 val obj = obj {201 "content" to ContainsDoubleQuotes202 }203 val representation = obj.toString()204 assertThat(representation).isValidJSON()205 assertThat(representation).isEqualTo("""{"content":"\"unfor\"tunate\""}""")206 }207 @Test208 fun `object with custom value containing backslashes and doublequotes char`() {209 val obj = obj {210 "content" to ContainsDoubleQuotesAndBackslashes211 }212 val representation = obj.toString()213 assertThat(representation).isValidJSON()214 assertThat(representation).isEqualTo("""{"content":"\"un\\for\"tuna\\te\""}""")215 }216 @Test217 fun `object with value containing new line`() {218 val obj = obj {219 "content" to "va\nlue"220 }221 val representation = obj.toString()222 assertThat(representation).isValidJSON()223 assertThat(representation).isEqualTo("""{"content":"va\nlue"}""")224 }225 @Test226 fun `object with custom value containing new line`() {227 val obj = obj {228 "content" to ContainsNewLines229 }230 val representation = obj.toString()231 assertThat(representation).isValidJSON()232 assertThat(representation).isEqualTo("""{"content":"unfor\ntunate"}""")233 }234 @Test235 fun `object with key containing backslash char`() {236 val obj = obj {237 "va\\lue" to "content"238 }239 val representation = obj.toString()240 assertThat(representation).isValidJSON()241 assertThat(representation).isEqualTo("""{"va\\lue":"content"}""")242 }243 @Test244 fun `object with key containing doublequotes char`() {245 val obj = obj {246 "va\"lue" to "content"247 }248 val representation = obj.toString()249 assertThat(representation).isValidJSON()250 assertThat(representation).isEqualTo("""{"va\"lue":"content"}""")251 }252 @Test253 fun `object with key containing newline`() {254 val obj = obj {255 "va\nlue" to "content"256 }257 val representation = obj.toString()258 assertThat(representation).isValidJSON()259 assertThat(representation).isEqualTo("""{"va\nlue":"content"}""")260 }261 @Test262 fun `object with value containing backslashes and doublequotes chars`() {263 val obj = obj {264 "content" to "[}[]}\\,{][,]\"\"\",\",,[,}}}[]],[}#{}"265 }266 val representation = obj.toString()267 assertThat(representation).isValidJSON()268 assertThat(representation).isEqualTo("""{"content":"[}[]}\\,{][,]\"\"\",\",,[,}}}[]],[}#{}"}""")269 }270 @Test271 fun `object with key containing backslashes and doublequotes chars`() {272 val obj = obj {273 "[}[]}\\,{][,]\"\"\",\",,[,}}}[]],[}#{}" to "content"274 }275 val representation = obj.toString()276 assertThat(representation).isValidJSON()277 assertThat(representation).isEqualTo("""{"[}[]}\\,{][,]\"\"\",\",,[,}}}[]],[}#{}":"content"}""")278 }279 @Test280 fun `array containing backslash char`() {281 val array = arr["va\\lue"]282 val representation = array.toString()283 assertThat(representation).isValidJSON()284 assertThat(representation).isEqualTo("""["va\\lue"]""")285 }286 @Test287 fun `array containing doublequotes char`() {288 val array = arr["va\"lue"]289 val representation = array.toString()290 assertThat(representation).isValidJSON()291 assertThat(representation).isEqualTo("""["va\"lue"]""")292 }293 @Test294 fun `array containing newline char`() {295 val array = arr["va\nlue"]296 val representation = array.toString()297 assertThat(representation).isValidJSON()298 assertThat(representation).isEqualTo("""["va\nlue"]""")299 }300 @Test301 fun `array containing backslashes and doublequotes chars`() {302 val array = arr["[}[]}\\,{][,]\"\"\",\",,[,}}}[]],[}#{}"]303 val representation = array.toString()304 assertThat(representation).isValidJSON()305 assertThat(representation).isEqualTo("""["[}[]}\\,{][,]\"\"\",\",,[,}}}[]],[}#{}"]""")306 }307 }308 @Nested309 inner class ContainingCases {310 @Test311 fun `object containing array`() {312 val representation = obj { "array" to arr }.toString()313 assertThat(representation).isValidJSON()314 assertThat(representation).isEqualTo("""{"array":[]}""")315 }316 @Test317 fun `array containing object`() {318 val representation = arr[obj { }].toString()319 assertThat(representation).isValidJSON()320 assertThat(representation).isEqualTo("[{}]")321 }322 @Test323 fun `object containing object`() {324 val representation = obj { "object" to obj { } }.toString()325 assertThat(representation).isValidJSON()326 assertThat(representation).isEqualTo("""{"object":{}}""")327 }328 @Test329 fun `array containing array`() {330 val representation = arr[arr].toString()331 assertThat(representation).isValidJSON()332 assertThat(representation).isEqualTo("[[]]")333 }334 @Test335 @Suppress("UNUSED_EXPRESSION")336 fun `object not containing a to() should do nothing`() {337 val representation = obj { "content" }.toString()338 assertThat(representation).isValidJSON()339 assertThat(representation).isEqualTo("{}")340 }341 }342 @Nested343 inner class MoreComplexCases {344 @Test345 fun `constructing a bit more complex object`() {346 val obj = obj {347 "key" to 3.4348 "anotherKey" to arr["test", "test2", 1, 2.433, true]349 "nullsAreAllowedToo" to null350 "array" to arr[351 obj {352 "double" to 33.4353 "float" to 345f354 "long" to 21L355 "int" to 42356 "char" to 'a'357 "byte" to 0xAA358 "otherArray" to arr359 "simpleObject" to SimpleObject360 }361 ]362 }363 val representation = obj.toString()364 assertThat(representation).isValidJSON()365 assertThat(representation)366 .isEqualTo("""{"key":3.4,"anotherKey":["test","test2",1,2.433,true],"nullsAreAllowedToo":null,"array":[{"double":33.4,"float":345.0,"long":21,"int":42,"char":"a","byte":170,"otherArray":[],"simpleObject":"SimpleObject"}]}""")367 }368 @Test369 fun `contructing a bit more complex array`() {370 val array = arr["koson", 33.4, 345f, 21L, 42, 'a', 0x21,371 obj {372 "aKey" to "value"373 "insideArray" to arr374 "otherArray" to arr["element", SimpleObject, obj { }]375 }376 ]377 val representation = array.toString()378 assertThat(representation).isValidJSON()379 assertThat(representation)380 .isEqualTo("""["koson",33.4,345.0,21,42,"a",33,{"aKey":"value","insideArray":[],"otherArray":["element","SimpleObject",{}]}]""")381 }382 @Test383 fun `testing an object inlined`() {384 val obj =385 obj { "key" to 3.4; "anotherKey" to arr["test", "test2", 1, 2.433, true]; "nullsAreAllowedToo" to null }386 val representation = obj.toString()387 assertThat(representation).isValidJSON()388 assertThat(representation)389 .isEqualTo("""{"key":3.4,"anotherKey":["test","test2",1,2.433,true],"nullsAreAllowedToo":null}""")390 }391 }392 @Nested393 inner class ExceptionCases {394 @Test395 fun `obj pretty with negative spaces must throw an IAE`() {396 try {397 obj { }.pretty(-3)398 fail { "No exception was thrown" }399 } catch (iae: IllegalArgumentException) {400 assertThat(iae.message!!).isEqualTo("spaces Int must be positive, but was -3.")401 }402 }403 @Test404 fun `array pretty with negative spaces must throw an IAE`() {405 try {406 arr.pretty(-5)407 fail { "No exception was thrown" }408 } catch (iae: IllegalArgumentException) {409 assertThat(iae.message!!).isEqualTo("spaces Int must be positive, but was -5.")410 }411 }412 }413 @Nested414 inner class RuntimeNullables {415 @Test416 fun `object with all nullable types must render`() {417 val string: String? = null418 val double: Double? = null419 val float: Float? = null420 val long: Long? = null421 val int: Int? = null422 val char: Char? = null423 val short: Short? = null424 val byte: Byte? = null425 val boolean: Boolean? = null426 val date: Date? = null427 val obj = obj {428 "string" to string429 "double" to double430 "float" to float431 "long" to long432 "int" to int433 "char" to char434 "short" to short435 "byte" to byte436 "boolean" to boolean437 "date" to date438 }439 val representation = obj.toString()440 assertThat(representation).isValidJSON()441 assertThat(representation).isEqualTo("""{"string":null,"double":null,"float":null,"long":null,"int":null,"char":null,"short":null,"byte":null,"boolean":null,"date":null}""")442 }443 @Test444 fun `object with all nullable Java types must render`() {445 val obj = obj {446 "string" to NullableTypes.STRING447 "double" to NullableTypes.DOUBLE448 "float" to NullableTypes.FLOAT449 "long" to NullableTypes.LONG450 "int" to NullableTypes.INT451 "char" to NullableTypes.CHAR452 "short" to NullableTypes.SHORT453 "byte" to NullableTypes.BYTE454 "boolean" to NullableTypes.BOOLEAN455 "date" to NullableTypes.DATE456 }457 val representation = obj.toString()458 assertThat(representation).isValidJSON()459 assertThat(representation).isEqualTo("""{"string":null,"double":null,"float":null,"long":null,"int":null,"char":null,"short":null,"byte":null,"boolean":null,"date":null}""")460 }461 @Test462 fun `array with all nullable types must render`() {463 val string: String? = null464 val double: Double? = null465 val float: Float? = null466 val long: Long? = null467 val int: Int? = null468 val char: Char? = null469 val short: Short? = null470 val byte: Byte? = null471 val boolean: Boolean? = null472 val date: Date? = null473 val array = arr[474 string,475 double,476 float,477 long,478 int,479 char,480 short,481 byte,482 boolean,483 date484 ]485 val representation = array.toString()486 assertThat(representation).isValidJSON()487 assertThat(representation).isEqualTo("[null,null,null,null,null,null,null,null,null,null]")488 }489 @Test490 fun `array with all nullable Java types must render`() {491 val array = arr[492 NullableTypes.STRING,493 NullableTypes.DOUBLE,494 NullableTypes.FLOAT,495 NullableTypes.LONG,496 NullableTypes.INT,497 NullableTypes.CHAR,498 NullableTypes.SHORT,499 NullableTypes.BYTE,500 NullableTypes.BOOLEAN,501 NullableTypes.DATE502 ]503 val representation = array.toString()504 assertThat(representation).isValidJSON()505 assertThat(representation).isEqualTo("[null,null,null,null,null,null,null,null,null,null]")506 }507 }508 @Nested509 inner class RawJsonContents {510 @Test511 fun `object with inner raw object`() {512 val obj = obj {513 "jsonContent" to rawJson("""{"menu":{"id":"file","value":"File","popup":{"menuitem":[{"value":"New","onclick":"CreateNewDoc()"},{"value":"Open","onclick":"OpenDoc()"},{"value":"Close","onclick":"CloseDoc()"}]}}}""")514 }515 val representation = obj.toString()516 assertThat(representation).isValidJSON()517 assertThat(representation).isEqualTo("""{"jsonContent":{"menu":{"id":"file","value":"File","popup":{"menuitem":[{"value":"New","onclick":"CreateNewDoc()"},{"value":"Open","onclick":"OpenDoc()"},{"value":"Close","onclick":"CloseDoc()"}]}}}}""")518 }519 @Test520 fun `array with inner raw object`() {521 val array =522 arr[rawJson("""{"menu":{"id":"file","value":"File","popup":{"menuitem":[{"value":"New","onclick":"CreateNewDoc()"},{"value":"Open","onclick":"OpenDoc()"},{"value":"Close","onclick":"CloseDoc()"}]}}}""")]523 val representation = array.toString()524 assertThat(representation).isValidJSON()525 assertThat(representation).isEqualTo("""[{"menu":{"id":"file","value":"File","popup":{"menuitem":[{"value":"New","onclick":"CreateNewDoc()"},{"value":"Open","onclick":"OpenDoc()"},{"value":"Close","onclick":"CloseDoc()"}]}}}]""")526 }527 @Test528 fun `object with null inner raw object`() {529 val obj = obj {530 "jsonContent" to rawJson(null)531 }532 val representation = obj.toString()533 assertThat(representation).isValidJSON()534 assertThat(representation).isEqualTo("""{"jsonContent":null}""")535 }536 @Test537 fun `array with null inner raw object`() {538 val array = arr[rawJson(null)]539 val representation = array.toString()540 assertThat(representation).isValidJSON()541 assertThat(representation).isEqualTo("[null]")542 }543 @Test544 fun `object with rawJson must be inlined properly when containing windows CR`() {545 val obj = obj {546 "jsonContent" to rawJson("{\r\n \"menu\":{\r\n \"id\":\"file\",\r\n \"value\":\"File\",\r\n \"popup\":{\r\n \"menuitem\":[\r\n {\r\n \"value\":\"New\",\r\n \"onclick\":\"CreateNewDoc()\"\r\n },\r\n {\r\n \"value\":\"Open\",\r\n \"onclick\":\"OpenDoc()\"\r\n },\r\n {\r\n \"value\":\"Close\",\r\n \"onclick\":\"CloseDoc()\"\r\n }\r\n ]\r\n }\r\n }\r\n}")547 }548 val representation = obj.toString()549 assertThat(representation).isValidJSON()550 assertThat(representation).isEqualTo("""{"jsonContent":{"menu":{"id":"file","value":"File","popup":{"menuitem":[{"value":"New","onclick":"CreateNewDoc()"},{"value":"Open","onclick":"OpenDoc()"},{"value":"Close","onclick":"CloseDoc()"}]}}}}""")551 }552 @Test553 fun `array with rawJson must be inlined properly when containing windows CR`() {554 val array =555 arr[rawJson("{\r\n \"menu\":{\r\n \"id\":\"file\",\r\n \"value\":\"File\",\r\n \"popup\":{\r\n \"menuitem\":[\r\n {\r\n \"value\":\"New\",\r\n \"onclick\":\"CreateNewDoc()\"\r\n },\r\n {\r\n \"value\":\"Open\",\r\n \"onclick\":\"OpenDoc()\"\r\n },\r\n {\r\n \"value\":\"Close\",\r\n \"onclick\":\"CloseDoc()\"\r\n }\r\n ]\r\n }\r\n }\r\n}")]556 val representation = array.toString()557 assertThat(representation).isValidJSON()558 assertThat(representation).isEqualTo("""[{"menu":{"id":"file","value":"File","popup":{"menuitem":[{"value":"New","onclick":"CreateNewDoc()"},{"value":"Open","onclick":"OpenDoc()"},{"value":"Close","onclick":"CloseDoc()"}]}}}]""")559 }560 @Test561 fun `object with rawJson must be inlined properly when containing UNIX CR`() {562 val obj = obj {563 "jsonContent" to rawJson("{\n \"menu\":{\n \"id\":\"file\",\n \"value\":\"File\",\n \"popup\":{\n \"menuitem\":[\n {\n \"value\":\"New\",\n \"onclick\":\"CreateNewDoc()\"\n },\n {\n \"value\":\"Open\",\n \"onclick\":\"OpenDoc()\"\n },\n {\n \"value\":\"Close\",\n \"onclick\":\"CloseDoc()\"\n }\n ]\n }\n }\n}")564 }565 val representation = obj.toString()566 assertThat(representation).isValidJSON()567 assertThat(representation).isEqualTo("""{"jsonContent":{"menu":{"id":"file","value":"File","popup":{"menuitem":[{"value":"New","onclick":"CreateNewDoc()"},{"value":"Open","onclick":"OpenDoc()"},{"value":"Close","onclick":"CloseDoc()"}]}}}}""")568 }569 @Test570 fun `array with rawJson must be inlined properly when containing UNIX CR`() {571 val array =572 arr[rawJson("{\n \"menu\":{\n \"id\":\"file\",\n \"value\":\"File\",\n \"popup\":{\n \"menuitem\":[\n {\n \"value\":\"New\",\n \"onclick\":\"CreateNewDoc()\"\n },\n {\n \"value\":\"Open\",\n \"onclick\":\"OpenDoc()\"\n },\n {\n \"value\":\"Close\",\n \"onclick\":\"CloseDoc()\"\n }\n ]\n }\n }\n}")]573 val representation = array.toString()574 assertThat(representation).isValidJSON()575 assertThat(representation).isEqualTo("""[{"menu":{"id":"file","value":"File","popup":{"menuitem":[{"value":"New","onclick":"CreateNewDoc()"},{"value":"Open","onclick":"OpenDoc()"},{"value":"Close","onclick":"CloseDoc()"}]}}}]""")576 }577 @Test578 fun `rawJson with emptyString should display empty string`() {579 val representation = obj {580 "jsonContent" to rawJson("")581 }.toString()582 assertThat(representation).isValidJSON()583 assertThat(representation).isEqualTo("""{"jsonContent":""}""")584 }585 @Test586 fun `rawJson with whitespaces string should display empty string`() {587 val representation = obj {588 "jsonContent" to rawJson(" ")589 }.toString()590 assertThat(representation).isValidJSON()591 assertThat(representation).isEqualTo("""{"jsonContent":""}""")592 }593 }594 @Nested595 inner class PrettyPrints {596 private val cr = System.lineSeparator()!!597 @Test598 fun `must pretty print an object`() {599 val pretty = obj {600 "key" to 3.4601 "string" to "newline\n"602 "anotherKey" to arr["test", "test2", 1, 2.433, true]603 "nullsAreAllowedToo" to null604 "array" to arr[605 obj {606 "double" to 33.4607 "float" to 345f608 "long" to 21L609 "int" to 42610 "char" to 'a'611 "byte" to 0xAA612 "otherArray" to arr613 "simpleObject" to SimpleObject614 "custom" to CustomizedKoson615 "raw" to rawJson("[]")616 "objectInside" to obj {617 "to" to 34618 "too" to "Dog"619 }620 "innerArray" to arr[621 34, 44, "to", null622 ]623 }624 ]625 }.pretty()626 assertThat(pretty).isValidJSON()627 assertThat(pretty).isEqualTo(628 "{$cr" +629 " \"key\": 3.4,$cr" +630 " \"string\": \"newline\\n\",$cr" +631 " \"anotherKey\": [$cr" +632 " \"test\",$cr" +633 " \"test2\",$cr" +634 " 1,$cr" +635 " 2.433,$cr" +636 " true$cr" +637 " ],$cr" +638 " \"nullsAreAllowedToo\": null,$cr" +639 " \"array\": [$cr" +640 " {$cr" +641 " \"double\": 33.4,$cr" +642 " \"float\": 345.0,$cr" +643 " \"long\": 21,$cr" +644 " \"int\": 42,$cr" +645 " \"char\": \"a\",$cr" +646 " \"byte\": 170,$cr" +647 " \"otherArray\": [$cr" +648 " $cr" +649 " ],$cr" +650 " \"simpleObject\": \"SimpleObject\",$cr" +651 " \"custom\": {$cr" +652 " \"custom\": 11$cr" +653 " },$cr" +654 " \"raw\": [],$cr" +655 " \"objectInside\": {$cr" +656 " \"to\": 34,$cr" +657 " \"too\": \"Dog\"$cr" +658 " },$cr" +659 " \"innerArray\": [$cr" +660 " 34,$cr" +661 " 44,$cr" +662 " \"to\",$cr" +663 " null$cr" +664 " ]$cr" +665 " }$cr" +666 " ]$cr" +667 "}"668 )669 }670 @Test671 fun `must pretty print an array`() {672 val pretty = arr[673 obj {674 "key" to 3.4675 "anotherKey" to arr["test", "test2", 1, 2.433, true]676 "nullsAreAllowedToo" to null677 "array" to arr[678 obj {679 "double" to 33.4680 "float" to 345f681 "long" to 21L682 "int" to 42683 "char" to 'a'684 "byte" to 0xAA685 "otherArray" to arr686 "simpleObject" to SimpleObject687 "custom" to CustomizedKoson688 "raw" to rawJson("[]")689 "objectInside" to obj {690 "to" to 34691 "too" to "Dog"692 }693 "innerArray" to arr[694 34, 44, "to", null695 ]696 }697 ]698 }699 ].pretty()700 assertThat(pretty).isValidJSON()701 assertThat(pretty).isEqualTo(702 "[$cr" +703 " {$cr" +704 " \"key\": 3.4,$cr" +705 " \"anotherKey\": [$cr" +706 " \"test\",$cr" +707 " \"test2\",$cr" +708 " 1,$cr" +709 " 2.433,$cr" +710 " true$cr" +711 " ],$cr" +712 " \"nullsAreAllowedToo\": null,$cr" +713 " \"array\": [$cr" +714 " {$cr" +715 " \"double\": 33.4,$cr" +716 " \"float\": 345.0,$cr" +717 " \"long\": 21,$cr" +718 " \"int\": 42,$cr" +719 " \"char\": \"a\",$cr" +720 " \"byte\": 170,$cr" +721 " \"otherArray\": [$cr" +722 " $cr" +723 " ],$cr" +724 " \"simpleObject\": \"SimpleObject\",$cr" +725 " \"custom\": {$cr" +726 " \"custom\": 11$cr" +727 " },$cr" +728 " \"raw\": [],$cr" +729 " \"objectInside\": {$cr" +730 " \"to\": 34,$cr" +731 " \"too\": \"Dog\"$cr" +732 " },$cr" +733 " \"innerArray\": [$cr" +734 " 34,$cr" +735 " 44,$cr" +736 " \"to\",$cr" +737 " null$cr" +738 " ]$cr" +739 " }$cr" +740 " ]$cr" +741 " }$cr" +742 "]"743 )744 }745 @Test746 internal fun `must pretty print a complex object`() {747 val complexObject = obj {748 "string" to "value"749 "int" to 9750 "double" to 7.6751 "float" to 3.2f752 "boolean" to false753 "object" to obj { }754 "emptyArray" to arr755 "array" to arr["test"]756 "null" to null757 "otherObj" to obj {758 "string" to "value"759 "int" to 9760 "double" to 7.6761 "float" to 3.2f762 "boolean" to false763 "object" to obj { }764 "emptyArray" to arr765 "array" to arr[766 obj {767 "string" to "value"768 "int" to 9769 "double" to 7.6770 "float" to 3.2f771 "boolean" to false772 "object" to obj { }773 "emptyArray" to arr774 "array" to arr["test"]775 "null" to null776 },777 obj {778 "string" to "value"779 "int" to 9780 "double" to 7.6781 "float" to 3.2f782 "boolean" to false783 "object" to obj { }784 "emptyArray" to arr785 "array" to arr["test"]786 "null" to null787 },788 obj {789 "string" to "value"790 "int" to 9791 "double" to 7.6792 "float" to 3.2f793 "boolean" to false794 "object" to obj { }795 "emptyArray" to arr796 "array" to arr[797 obj {798 "string" to "value"799 "int" to 9800 "double" to 7.6801 "float" to 3.2f802 "boolean" to false803 "object" to obj { }804 "emptyArray" to arr805 "array" to arr["test"]806 "null" to null807 },808 obj {809 "string" to "value"810 "int" to 9811 "double" to 7.6812 "float" to 3.2f813 "boolean" to false814 "object" to obj { }815 "emptyArray" to arr816 "array" to arr[45, 12.4, 9.4, true, false, true, null, 45, 12.4, 9.4, true, false, true, null, 45, 12.4, 9.4, true, false, true, null, 45, 12.4, 9.4, true, false, true, null, 45, 12.4, 9.4, true, false, true, null]817 "null" to null818 }819 ]820 "null" to null821 }822 ]823 "null" to obj {824 "string" to "value"825 "int" to 9826 "double" to 7.6827 "float" to 3.2f828 "boolean" to false829 "object" to obj { }830 "emptyArray" to arr831 "array" to arr[832 obj {833 "string" to "value"834 "int" to 9835 "double" to 7.6836 "float" to 3.2f837 "boolean" to false838 "object" to obj { }839 "emptyArray" to arr840 "array" to arr["test"]841 "null" to null842 },843 obj {844 "string" to "value"845 "int" to 9846 "double" to 7.6847 "float" to 3.2f848 "boolean" to false849 "object" to obj { }850 "emptyArray" to arr851 "array" to arr[45, 12.4, 9.4, true, false, true, null, 45, 12.4, 9.4, true, false, true, null, 45, 12.4, 9.4, true, false, true, null, 45, 12.4, 9.4, true, false, true, null, 45, 12.4, 9.4, true, false, true, null]852 "null" to null853 }854 ]855 "null" to null856 "onceAgain" to obj {857 "string" to "value"858 "int" to 9859 "double" to 7.6860 "float" to 3.2f861 "boolean" to false862 "object" to obj { }863 "emptyArray" to arr864 "array" to arr["test"]865 "null" to null866 "otherObj" to obj {867 "string" to "value"868 "int" to 9869 "double" to 7.6870 "float" to 3.2f871 "boolean" to false872 "object" to obj { }873 "emptyArray" to arr874 "array" to arr[875 obj {876 "string" to "value"877 "int" to 9878 "double" to 7.6879 "float" to 3.2f880 "boolean" to false881 "object" to obj { }882 "emptyArray" to arr883 "array" to arr["test"]884 "null" to null885 },886 obj {887 "string" to "value"888 "int" to 9889 "double" to 7.6890 "float" to 3.2f891 "boolean" to false892 "object" to obj { }893 "emptyArray" to arr894 "array" to arr["test"]895 "null" to null896 },897 obj {898 "string" to "value"899 "int" to 9900 "double" to 7.6901 "float" to 3.2f902 "boolean" to false903 "object" to obj { }904 "emptyArray" to arr905 "array" to arr[906 obj {907 "string" to "value"908 "int" to 9909 "double" to 7.6910 "float" to 3.2f911 "boolean" to false912 "object" to obj { }913 "emptyArray" to arr914 "array" to arr["test"]915 "null" to null916 },917 obj {918 "string" to "value"919 "int" to 9920 "double" to 7.6921 "float" to 3.2f922 "boolean" to false923 "object" to obj { }924 "emptyArray" to arr925 "array" to arr[45, 12.4, 9.4, true, false, true, null, 45, 12.4, 9.4, true, false, true, null, 45, 12.4, 9.4, true, false, true, null, 45, 12.4, 9.4, true, false, true, null, 45, 12.4, 9.4, true, false, true, null]926 "null" to null927 }928 ]929 "null" to null930 }931 ]932 "null" to obj {933 "string" to "value"934 "int" to 9935 "double" to 7.6936 "float" to 3.2f937 "boolean" to false938 "object" to obj { }939 "emptyArray" to arr940 "array" to arr[941 obj {942 "string" to "value"943 "int" to 9944 "double" to 7.6945 "float" to 3.2f946 "boolean" to false947 "object" to obj { }948 "emptyArray" to arr949 "array" to arr["test"]950 "null" to null951 },952 obj {953 "string" to "value"954 "int" to 9955 "double" to 7.6956 "float" to 3.2f957 "boolean" to false958 "object" to obj { }959 "emptyArray" to arr960 "array" to arr[45, 12.4, 9.4, true, false, true, null, 45, 12.4, 9.4, true, false, true, null, 45, 12.4, 9.4, true, false, true, null, 45, 12.4, 9.4, true, false, true, null, 45, 12.4, 9.4, true, false, true, null]961 "null" to null962 }963 ]964 "null" to null965 }966 }967 "anotherObj" to obj {968 "string" to "value"969 "int" to 9970 "double" to 7.6971 "float" to 3.2f972 "boolean" to false973 "object" to obj { }974 "emptyArray" to arr975 "array" to arr["test"]976 "null" to null977 }978 }979 }980 }981 "anotherObj" to obj {982 "string" to "value"983 "int" to 9984 "double" to 7.6985 "float" to 3.2f986 "boolean" to false987 "object" to obj { }988 "emptyArray" to arr989 "array" to arr["test"]990 "null" to null991 }992 }993 assertThat(complexObject.toString()).isValidJSON()994 assertThat(complexObject.pretty(1)).isValidJSON()995 assertThat(complexObject.pretty(2)).isValidJSON()996 assertThat(complexObject.pretty(3)).isValidJSON()997 assertThat(complexObject.pretty(4)).isValidJSON()998 }999 }...

Full Screen

Full Screen

OpenGlToCameraHelperTest.kt

Source:OpenGlToCameraHelperTest.kt Github

copy

Full Screen

...244 // [0.0 1.5806589 0.009158132 0.0 ]245 // [0.0 0.0 -1.002002 -0.2002002 ]246 // [0.0 0.0 -1.0 0.0 ]247 // android.opengl.Matrix defines values column-wise248 return floatArrayOf(249 2.8693345f, 0.0f, 0.0f, 0.0f,250 0.0f, 1.5806589f, 0.0f, 0.0f,251 -0.004545755f, 0.009158132f, -1.002002f, -1.0f,252 0.0f, 0.0f, -0.2002002f, 0.0f253 )254 }255 private fun createRotation(): Rotation3D {256 val randomizer = UniformRandomizer()257 val roll = Math.toRadians(258 randomizer.nextDouble(259 MIN_ROTATION_ANGLE_DEGREES,260 MAX_ROTATION_ANGLE_DEGREES261 )262 )...

Full Screen

Full Screen

StraightHashMapEnvTests.kt

Source:StraightHashMapEnvTests.kt Github

copy

Full Screen

1package dev.evo.persistent.hashmap.straight2import dev.evo.persistent.VersionedDirectoryException3import dev.evo.persistent.hashmap.Dummy324import dev.evo.persistent.hashmap.Knuth325import dev.evo.persistent.util.withTempDir6import io.kotest.assertions.throwables.shouldThrow7import io.kotest.core.spec.style.FunSpec8import io.kotest.matchers.shouldBe9class StraightHashMapEnvTests : FunSpec() {10 init {11 test("env: single writer, multiple readers") {12 withTempDir { tmpDir ->13 StraightHashMapEnv.Builder(StraightHashMapType_Int_Float)14 .useUnmapHack(true)15 .open(tmpDir)16 .use { env ->17 env.getCurrentVersion() shouldBe 0L18 StraightHashMapEnv.Builder(StraightHashMapType_Int_Float)19 .useUnmapHack(true)20 .openReadOnly(tmpDir)21 .use { roEnv ->22 roEnv.getCurrentVersion() shouldBe 0L23 }24 shouldThrow<VersionedDirectoryException> {25 StraightHashMapEnv.Builder(StraightHashMapType_Int_Float)26 .open(tmpDir)27 }28 }29 StraightHashMapEnv.Builder(StraightHashMapType_Int_Float)30 .useUnmapHack(true)31 .open(tmpDir)32 .use { env ->33 env.getCurrentVersion() shouldBe 0L34 }35 }36 }37 test("env: new map") {38 withTempDir { tmpDir ->39 StraightHashMapEnv.Builder(StraightHashMapType_Int_Float)40 .useUnmapHack(true)41 .open(tmpDir)42 .use { env ->43 env.openMap().use { map ->44 map.put(1, 1.1F) shouldBe PutResult.OK45 map.put(2, 1.2F) shouldBe PutResult.OK46 env.getCurrentVersion() shouldBe 0L47 StraightHashMapEnv.Builder(StraightHashMapType_Int_Float)48 .useUnmapHack(true)49 .openReadOnly(tmpDir)50 .use { roEnv ->51 env.newMap(map, map.maxEntries).use { newMap ->52 newMap.put(1, 11F) shouldBe PutResult.OK53 newMap.put(2, 12F) shouldBe PutResult.OK54 env.getCurrentVersion() shouldBe 0L55 roEnv.getCurrentVersion() shouldBe 0L56 roEnv.getCurrentMap().use { roMap ->57 roMap.get(1, 0F) shouldBe 1.1F58 }59 env.discard(newMap)60 }61 env.newMap(map, map.maxEntries).use { newMap ->62 newMap.put(1, 111F) shouldBe PutResult.OK63 env.getCurrentVersion() shouldBe 0L64 roEnv.getCurrentVersion() shouldBe 0L65 env.commit(newMap)66 roEnv.getCurrentVersion() shouldBe 1L67 roEnv.getCurrentMap().use { roMap ->68 roMap.get(1, 0F) shouldBe 111F69 roMap.get(2, 0F) shouldBe 0F70 }71 newMap.put(2, 112F) shouldBe PutResult.OK72 roEnv.getCurrentMap().use { roMap ->73 roMap.get(1, 0F) shouldBe 111F74 roMap.get(2, 0F) shouldBe 112F75 }76 }77 }78 }79 }80 }81 }82 test("env: new map should preserve bookmarks") {83 withTempDir { tmpDir ->84 StraightHashMapEnv.Builder(StraightHashMapType_Int_Float)85 .useUnmapHack(true)86 .open(tmpDir)87 .use { env ->88 env.openMap().use { map ->89 map.storeBookmark(0, 0xCAFE_BABE)90 map.loadBookmark(0) shouldBe 0xCAFE_BABE91 env.newMap(map, map.maxEntries).use { newMap ->92 newMap.loadBookmark(0) shouldBe 0xCAFE_BABE93 newMap.storeBookmark(0, 0xDEAD_BEEF)94 env.commit(newMap)95 }96 }97 }98 StraightHashMapEnv.Builder(StraightHashMapType_Int_Float)99 .useUnmapHack(true)100 .open(tmpDir)101 .use { env ->102 env.openMap().use { map ->103 map.loadBookmark(0) shouldBe 0xDEAD_BEEF104 }105 }106 }107 }108 test("env: copy map") {109 withTempDir { tmpDir ->110 StraightHashMapEnv.Builder(StraightHashMapType_Int_Float)111 .useUnmapHack(true)112 .open(tmpDir)113 .use { env ->114 env.openMap().use { map ->115 map.put(1, 1.1F) shouldBe PutResult.OK116 map.put(2, 1.2F) shouldBe PutResult.OK117 env.getCurrentVersion() shouldBe 0L118 StraightHashMapEnv.Builder(StraightHashMapType_Int_Float)119 .useUnmapHack(true)120 .openReadOnly(tmpDir)121 .use { roEnv ->122 roEnv.getCurrentVersion() shouldBe 0L123 val mapV0 = roEnv.getCurrentMap()124 env.copyMap(map).use { newMap ->125 env.getCurrentVersion() shouldBe 0L126 newMap.put(3, 1.3F) shouldBe PutResult.OK127 roEnv.getCurrentVersion() shouldBe 0L128 env.commit(newMap)129 roEnv.getCurrentVersion() shouldBe 1L130 }131 val mapV1 = roEnv.getCurrentMap()132 mapV0.version shouldBe 0L133 mapV0.maxEntries shouldBe 1024134 mapV0.capacity shouldBe 1597135 mapV0.get(1, 0.0F) shouldBe 1.1F136 mapV0.get(2, 0.0F) shouldBe 1.2F137 mapV0.get(3, 0.0F) shouldBe 0.0F138 mapV1.version shouldBe 1L139 mapV1.maxEntries shouldBe 4140 mapV1.capacity shouldBe 7141 mapV1.get(1, 0.0F) shouldBe 1.1F142 mapV1.get(2, 0.0F) shouldBe 1.2F143 mapV1.get(3, 0.0F) shouldBe 1.3F144 mapV0.close()145 mapV1.close()146 }147 }148 }149 }150 }151 test("env: anonymous") {152 StraightHashMapEnv.Builder(StraightHashMapType_Int_Float)153 .useUnmapHack(true)154 .createAnonymousHeap()155 .use { env ->156 env.openMap()157 }158 }159 test("env: change hashing") {160 withTempDir { tmpDir ->161 StraightHashMapEnv.Builder(StraightHashMapType_Int_Float)162 .hasher(Dummy32)163 .useUnmapHack(true)164 .open(tmpDir)165 .use { env ->166 env.openMap().use { map ->167 map as StraightHashMapImpl_Int_Float168 map.header.hasher shouldBe Dummy32169 map.put(1, 1.1F) shouldBe PutResult.OK170 }171 }172 StraightHashMapEnv.Builder(StraightHashMapType_Int_Float)173 .hasher(Knuth32)174 .useUnmapHack(true)175 .open(tmpDir)176 .use { env ->177 env.openMap().use { map ->178 map as StraightHashMapImpl_Int_Float179 map.header.hasher shouldBe Dummy32180 StraightHashMapEnv.Builder(StraightHashMapType_Int_Float)181 .useUnmapHack(true)182 .openReadOnly(tmpDir)183 .use { roEnv ->184 (roEnv.getCurrentMap() as StraightHashMapROImpl_Int_Float).header.hasher shouldBe Dummy32185 env.copyMap(map).use { newMap ->186 newMap as StraightHashMapImpl_Int_Float187 newMap.header.hasher shouldBe Knuth32188 env.commit(newMap)189 }190 val roMap = roEnv.getCurrentMap()191 (roMap as StraightHashMapROImpl_Int_Float).header.hasher shouldBe Knuth32192 roMap.get(1, 0.0F) shouldBe 1.1F193 }194 }195 }196 }197 }198 }199}...

Full Screen

Full Screen

MenuActivity.kt

Source:MenuActivity.kt Github

copy

Full Screen

1package com.example.usercenter.ui.activity2import android.animation.*3import android.app.Activity4import android.os.Bundle5import android.view.View6import android.view.animation.BounceInterpolator7import android.widget.ImageView8import com.example.usercenter.R9import com.example.usercenter.test.MyEvaluator10import kotlinx.android.synthetic.main.activity_menu.*11class MenuActivity : Activity() {12 private var isOpen = false13 override fun onCreate(savedInstanceState: Bundle?) {14 super.onCreate(savedInstanceState)15 setContentView(R.layout.activity_menu)16 initEvent()17 }18 private fun initEvent() {19 test.setOnClickListener {20 // val animator: ValueAnimator = AnimatorInflater.loadAnimator(this, R.animator.animator) as ValueAnimator21// animator.addUpdateListener { animation ->22// val off = animation!!.animatedValue as Int23// test.layout(off, off, off + test.width, off + test.height)24// }25// val keyframe = Keyframe.ofObject(0f,'A')26//27 test.animate().scaleX(1.0f).scaleXBy(1.1f).setListener(object: Animator.AnimatorListener {28 override fun onAnimationRepeat(animation: Animator?) {29 }30 override fun onAnimationEnd(animation: Animator?) {31 }32 override fun onAnimationCancel(animation: Animator?) {33 }34 override fun onAnimationStart(animation: Animator?) {35 }36 })37// animator.start()38// val propertyValuesHolder = PropertyValuesHolder.ofFloat("Rotation",60f,-60f,40f,-40f,-20f,20f,10f,-10f,0f)39// val propertyValuesHolderAlpha = PropertyValuesHolder.ofFloat("alpha",0.1f,1f,0.1f,1f)40// val objectAnimator = ObjectAnimator.ofPropertyValuesHolder(test,propertyValuesHolder,propertyValuesHolderAlpha)41// objectAnimator.duration = 200042// objectAnimator.start()43// val keyFrame = Keyframe.ofFloat(0.1f, 20f)44// val keyFrame1 = Keyframe.ofFloat(0.2f, -20f)45// keyFrame.interpolator = BounceInterpolator()46// val keyFrame2 = Keyframe.ofFloat(0.3f, 20f)47// val keyFrame3 = Keyframe.ofFloat(0.4f, -20f)48// val keyFrame4 = Keyframe.ofFloat(0.5f, 20f)49// keyFrame4.interpolator = BounceInterpolator()50// val keyFrame5 = Keyframe.ofFloat(0.6f, -20f)51// val keyFrame6 = Keyframe.ofFloat(0.7f, 20f)52// val keyFrame7 = Keyframe.ofFloat(0.8f, -20f)53// val keyFrame8 = Keyframe.ofFloat(0.9f, 20f)54// val keyFrame9 = Keyframe.ofFloat(1.0f, 36f)55//56// val propertyValuesHolder = PropertyValuesHolder.ofKeyframe("rotation", keyFrame, keyFrame1, keyFrame2, keyFrame3, keyFrame4, keyFrame5, keyFrame6, keyFrame7, keyFrame8, keyFrame9)57// val objectAnimator = ObjectAnimator.ofPropertyValuesHolder(testView, propertyValuesHolder)58//// objectAnimator.addUpdateListener {59//// testView.setMyValue(it.animatedValue as Char)60//// }61// objectAnimator.duration = 200062// objectAnimator.start()63 }64 mMenuImage.setOnClickListener {65 isOpen = if (!isOpen) {66 openMenu(menuOne, 0)67 openMenu(menuTwo, 1)68 openMenu(menuThree, 2)69 openMenu(menuFour, 3)70 openMenu(menuFive, 4)71 true72 } else {73 closeMenu(menuOne, 0)74 closeMenu(menuTwo, 1)75 closeMenu(menuThree, 2)76 closeMenu(menuFour, 3)77 closeMenu(menuFive, 4)78 false79 }80 }81 }82 private fun closeMenu(view: ImageView, index: Int) {83 if (view.visibility != View.VISIBLE) {84 view.visibility = View.VISIBLE85 }86 val radians = Math.toRadians(180.0) / 4 * index87 val pointX = -400 * Math.sin(radians)88 val pointY = -400 * Math.cos(radians)89 val objectAnimatorX = ObjectAnimator.ofFloat(view, "TranslationX", pointX.toFloat(), 0f)90 val objectAnimatorY = ObjectAnimator.ofFloat(view, "TranslationY", pointY.toFloat(), 0f)91 val objectAnimatorScaleX = ObjectAnimator.ofFloat(view, "ScaleX", 1f, 0f)92 val objectAnimatorScaleY = ObjectAnimator.ofFloat(view, "ScaleY", 1f, 0f)93 val objectAnimatorAlpha = ObjectAnimator.ofFloat(view, "alpha", 1f, 0.1f)94 val animatorSet = AnimatorSet()95 animatorSet.playTogether(objectAnimatorX, objectAnimatorY, objectAnimatorScaleX, objectAnimatorScaleY, objectAnimatorAlpha)96 animatorSet.duration = 200097 animatorSet.start()98 }99 private fun openMenu(view: ImageView, index: Int) {100 if (view.visibility != View.VISIBLE) {101 view.visibility = View.VISIBLE102 }103 val pointX: Double104 val pointY: Double105 val radians: Double106 pointX = if (index > 2) {107 radians = Math.toRadians(90.0) / 2 * (index - 2)108 400 * Math.sin(radians)109 } else {110 radians = Math.toRadians(90.0) / 2 * index111 -400 * Math.sin(radians)112 }113 pointY = -400 * Math.cos(radians)114 val objectAnimatorX = ObjectAnimator.ofFloat(view, "TranslationX", 0f, pointX.toFloat())115 val objectAnimatorY = ObjectAnimator.ofFloat(view, "TranslationY", 0f, pointY.toFloat())116 val objectAnimatorScaleX = ObjectAnimator.ofFloat(view, "ScaleX", 0f, 1f)117 val objectAnimatorScaleY = ObjectAnimator.ofFloat(view, "ScaleY", 0f, 1f)118 val objectAnimatorAlpha = ObjectAnimator.ofFloat(view, "alpha", 0f, 1f)119 val animatorSet = AnimatorSet()120 animatorSet.playTogether(objectAnimatorX, objectAnimatorY, objectAnimatorScaleX, objectAnimatorScaleY, objectAnimatorAlpha)121 animatorSet.duration = 500122 animatorSet.interpolator = BounceInterpolator()123 animatorSet.start()124 }125}...

Full Screen

Full Screen

KNumTest.kt

Source:KNumTest.kt Github

copy

Full Screen

...7 callback()8 }9 @Test10 fun addVectors() = knumTest {11 assertEquals(listOf(6f, 8f, 10f, 12f), (floatArrayOf(1f, 2f, 3f, 4f).const + floatArrayOf(5f, 6f, 7f, 8f).const).compute().getFloatArray().toList())12 }13 @Test14 fun addVectorScalar() = knumTest {15 assertEquals(listOf(2f, 3f, 4f, 5f), (floatArrayOf(1f, 2f, 3f, 4f).const + 1f).compute().getFloatArray().toList())16 }17 @Test18 fun mulVectors() = knumTest {19 assertEquals(listOf(-1f, -4f, -9f, -16f), (floatArrayOf(1f, 2f, 3f, 4f).const * floatArrayOf(-1f, -2f, -3f, -4f).const).compute().getFloatArray().toList())20 }21 @Test22 fun mulVectorScalar() = knumTest {23 assertEquals(listOf(2f, 4f, 6f, 8f), (floatArrayOf(1f, 2f, 3f, 4f).const * 2f).compute().getFloatArray().toList())24 }25 @Test26 fun minVectors() = knumTest {27 assertEquals(listOf(-1f, -1f, -1f, 1f, -2f, 2f, -1f, 0f), min(floatArrayOf(-1f, 1f, -1f, 1f, 2f, 2f, 0f, 0f).const, floatArrayOf(1f, -1f, -1f, 1f, -2f, 2f, -1f, 0f).const).compute().getFloatArray().toList())28 }29 @Test30 fun maxVectors() = knumTest {31 assertEquals(listOf(1f, 1f, -1f, 1f, 2f, 2f, 0f, 0f), max(floatArrayOf(-1f, 1f, -1f, 1f, 2f, 2f, 0f, 0f).const, floatArrayOf(1f, -1f, -1f, 1f, -2f, 2f, -1f, 0f).const).compute().getFloatArray().toList())32 }33 @Test34 fun pad() = knumTest {35 assertEquals(36 listOf(37 0f, 0f, 0f, 0f,38 0f, 1f, 2f, 0f,39 0f, 3f, 4f, 0f,40 0f, 0f, 0f, 0f41 ),42 floatArrayOf(1f, 2f, 3f, 4f).const.reshape(2, 2).pad(1, 1).compute().getFloatArray().toList()43 )44 }45 @Test46 open fun conv2d() = knumTest {47 assertEquals(48 listOf(49 77f, 67f,50 47f, 37f51 ),52 floatArrayOf(1f, 2f, 3f, 4f).const.reshape(2, 2).pad(1, 1).conv2d(floatArrayOf(53 1f, 2f, 3f,54 4f, 5f, 6f,55 7f, 8f, 9f56 ).const(3, 3)).compute().getFloatArray().toList()57 )58 }59 @Test60 open fun conv2db() = knumTest {61 assertEquals(62 listOf(63 1f, 2f,64 3f, 4f65 ),66 floatArrayOf(1f, 2f, 3f, 4f).const.reshape(2, 2).pad(1, 1).conv2d(floatArrayOf(67 0f, 0f, 0f,68 0f, 1f, 0f,69 0f, 0f, 0f70 ).const(3, 3)).compute().getFloatArray().toList()71 )72 }73 @Test74 open fun conv2dc() = knumTest {75 assertEquals(76 listOf(77 4f, 0f,78 0f, 0f79 ),80 floatArrayOf(1f, 2f, 3f, 4f).const.reshape(2, 2).pad(1, 1).conv2d(floatArrayOf(81 0f, 0f, 0f,82 0f, 0f, 0f,83 0f, 0f, 1f84 ).const(3, 3)).compute().getFloatArray().toList()85 )86 }87 @Test88 open fun conv2dd() = knumTest {89 assertEquals(90 listOf(91 0f, 0f,92 0f, 1f93 ),94 floatArrayOf(1f, 2f, 3f, 4f).const.reshape(2, 2).pad(1, 1).conv2d(floatArrayOf(95 1f, 0f, 0f,96 0f, 0f, 0f,97 0f, 0f, 0f98 ).const(3, 3)).compute().getFloatArray().toList()99 )100 }101 @Test102 open fun conv2de() = knumTest {103 assertEquals(104 listOf(105 0f, 0f,106 2f, 0f107 ),108 floatArrayOf(1f, 2f, 3f, 4f).const.reshape(2, 2).pad(1, 1).conv2d(floatArrayOf(109 0f, 0f, 1f,110 0f, 0f, 0f,111 0f, 0f, 0f112 ).const(3, 3)).compute().getFloatArray().toList()113 )114 }115 @Test116 open fun conv2dBig() = knumTest {117 assertEquals(118 listOf(119 1f, 2f, 3f, 4f,120 5f, 6f, 7f, 8f,121 9f, 10f, 11f, 12f,122 13f, 14f, 15f, 16f123 ),124 floatArrayOf(125 1f, 2f, 3f, 4f,126 5f, 6f, 7f, 8f,127 9f, 10f, 11f, 12f,128 13f, 14f, 15f, 16f129 ).const.reshape(4, 4).pad(1, 1).conv2d(floatArrayOf(130 0f, 0f, 0f,131 0f, 1f, 0f,132 0f, 0f, 0f133 ).const(3, 3)).compute().getFloatArray().toList()134 )135 }136}...

Full Screen

Full Screen

withManyDefaultParams.kt

Source:withManyDefaultParams.kt Github

copy

Full Screen

1public open class Test(_myName : String?, _a : Boolean, _b : Double, _c : Float, _d : Long, _e : Int, _f : Short, _g : Char) {2private val myName : String?3private var a : Boolean = false4private var b : Double = 0.toDouble()5private var c : Float = 0.toFloat()6private var d : Long = 07private var e : Int = 08private var f : Short = 09private var g : Char = ' '10{11myName = _myName12a = _a13b = _b14c = _c15d = _d16e = _e17f = _f18g = _g19}20class object {21public open fun init() : Test {22val __ = Test(null, false, 0.toDouble(), 0.toFloat(), 0, 0, 0, ' ')23return __24}25public open fun init(name : String?) : Test {26val __ = Test(foo(name), false, 0.toDouble(), 0.toFloat(), 0, 0, 0, ' ')27return __28}29open fun foo(n : String?) : String? {30return ""31}32}33}34public open class User() {35class object {36public open fun main() : Unit {37var t : Test? = Test.init("name")38}39}...

Full Screen

Full Screen

endsWithDFL.kt

Source:endsWithDFL.kt Github

copy

Full Screen

1open class Test() {2open fun test() : Unit {3var l1 : Long = 104var d1 : Double = 10.05var f1 : Float = 10.0.toFloat()6var l2 : Long = 107var d2 : Double = 10.08var f2 : Float = 10.0.toFloat()9}10open fun testBoxed() : Unit {11var l1 : Long? = 1012var d1 : Double? = 10.013var f1 : Float? = 10.0.toFloat()14var l2 : Long? = 1015var d2 : Double? = 10.016var f2 : Float? = 10.0.toFloat()17}...

Full Screen

Full Screen

float

Using AI Code Generation

copy

Full Screen

1 test.Open i = new test.Open();2 i.inte();3 System.out.println("The float value is: " + i.f);4 System.out.println("The double value is: " + i.d);5 System.out.println("The int value is: " + i.i);6 }7}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful