Skip to content

Commit

Permalink
Convert ColorUtilTest to Kotlin (#38979)
Browse files Browse the repository at this point in the history
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
okwasniewski authored and facebook-github-bot committed Sep 4, 2023
1 parent 83885f1 commit 7f26b08
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 52 deletions.

This file was deleted.

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))
}
}

0 comments on commit 7f26b08

Please sign in to comment.