-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert ColorUtilTest to Kotlin (#38979)
Summary: Converts ColorUtilTest to kotlin as requested in #38825 ## Changelog: [INTERNAL] [CHANGED] - Convert ColorUtilTest to Kotlin Pull Request resolved: #38979 Test Plan: 1. Run `./gradlew :packages:react-native:ReactAndroid:test`. 2. All tests should pass. Reviewed By: fkgozali, cortinico, arushikesarwani94 Differential Revision: D48802302 Pulled By: mdvacca fbshipit-source-id: 876caf288bd5df1e1fdc4b0b20b41afdfacf364f
- Loading branch information
1 parent
83885f1
commit 7f26b08
Showing
2 changed files
with
49 additions
and
52 deletions.
There are no files selected for viewing
52 changes: 0 additions & 52 deletions
52
.../react-native/ReactAndroid/src/test/java/com/facebook/react/views/view/ColorUtilTest.java
This file was deleted.
Oops, something went wrong.
49 changes: 49 additions & 0 deletions
49
...es/react-native/ReactAndroid/src/test/java/com/facebook/react/views/view/ColorUtilTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
|
||
package com.facebook.react.views.view | ||
|
||
import android.graphics.PixelFormat | ||
import junit.framework.TestCase.assertEquals | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.robolectric.RobolectricTestRunner | ||
|
||
/** Based on Fresco's DrawableUtilsTest (https://github.com/facebook/fresco). */ | ||
@RunWith(RobolectricTestRunner::class) | ||
class ColorUtilTest { | ||
@Test | ||
fun testMultiplyColorAlpha() { | ||
assertEquals(0x00123456U.toInt(), ColorUtil.multiplyColorAlpha(0xC0123456U.toInt(), 0)) | ||
assertEquals(0x07123456U.toInt(), ColorUtil.multiplyColorAlpha(0xC0123456U.toInt(), 10)) | ||
assertEquals(0x96123456U.toInt(), ColorUtil.multiplyColorAlpha(0xC0123456U.toInt(), 200)) | ||
assertEquals(0xC0123456U.toInt(), ColorUtil.multiplyColorAlpha(0xC0123456U.toInt(), 255)) | ||
} | ||
|
||
@Test | ||
fun testGetOpacityFromColor() { | ||
assertEquals(PixelFormat.TRANSPARENT, ColorUtil.getOpacityFromColor(0x00000000)) | ||
assertEquals(PixelFormat.TRANSPARENT, ColorUtil.getOpacityFromColor(0x00123456)) | ||
assertEquals(PixelFormat.TRANSPARENT, ColorUtil.getOpacityFromColor(0x00FFFFFF)) | ||
assertEquals(PixelFormat.TRANSLUCENT, ColorUtil.getOpacityFromColor(0xC0000000.toInt())) | ||
assertEquals(PixelFormat.TRANSLUCENT, ColorUtil.getOpacityFromColor(0xC0123456.toInt())) | ||
assertEquals(PixelFormat.TRANSLUCENT, ColorUtil.getOpacityFromColor(0xC0FFFFFF.toInt())) | ||
assertEquals(PixelFormat.OPAQUE, ColorUtil.getOpacityFromColor(0xFF000000.toInt())) | ||
assertEquals(PixelFormat.OPAQUE, ColorUtil.getOpacityFromColor(0xFF123456.toInt())) | ||
assertEquals(PixelFormat.OPAQUE, ColorUtil.getOpacityFromColor(0xFFFFFFFF.toInt())) | ||
} | ||
|
||
@Test | ||
fun testNormalize() { | ||
assertEquals(0x800B1621U.toInt(), ColorUtil.normalize(11.0, 22.0, 33.0, 0.5)) | ||
assertEquals(0x00000000U.toInt(), ColorUtil.normalize(0.0, 0.0, 0.0, 0.0)) | ||
assertEquals(0xFFFFFFFFU.toInt(), ColorUtil.normalize(255.0, 255.0, 255.0, 1.0)) | ||
assertEquals(0xFF00FFFFU.toInt(), ColorUtil.normalize(-1.0, 256.0, 255.0, 1.1)) | ||
assertEquals(0x000001FFU.toInt(), ColorUtil.normalize(0.4, 0.5, 255.4, -1.0)) | ||
} | ||
} |