Добавлена проверка Boolean чисел по регистру
This commit is contained in:
15
.idea/checkstyle-idea.xml
generated
Normal file
15
.idea/checkstyle-idea.xml
generated
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="CheckStyle-IDEA" serialisationVersion="2">
|
||||||
|
<checkstyleVersion>13.4.2</checkstyleVersion>
|
||||||
|
<scanScope>JavaOnly</scanScope>
|
||||||
|
<option name="thirdPartyClasspath" />
|
||||||
|
<option name="activeLocationIds" />
|
||||||
|
<option name="locations">
|
||||||
|
<list>
|
||||||
|
<ConfigurationLocation id="bundled-sun-checks" type="BUNDLED" scope="All" description="Sun Checks">(bundled)</ConfigurationLocation>
|
||||||
|
<ConfigurationLocation id="bundled-google-checks" type="BUNDLED" scope="All" description="Google Checks">(bundled)</ConfigurationLocation>
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
14
.idea/discord.xml
generated
Normal file
14
.idea/discord.xml
generated
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="DiscordProjectSettings">
|
||||||
|
<option name="show" value="PROJECT_FILES" />
|
||||||
|
<option name="description" value="" />
|
||||||
|
<option name="applicationTheme" value="default" />
|
||||||
|
<option name="iconsTheme" value="default" />
|
||||||
|
<option name="button1Title" value="" />
|
||||||
|
<option name="button1Url" value="" />
|
||||||
|
<option name="button2Title" value="" />
|
||||||
|
<option name="button2Url" value="" />
|
||||||
|
<option name="customApplicationId" value="" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
2
.idea/vcs.xml
generated
2
.idea/vcs.xml
generated
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="VcsDirectoryMappings">
|
<component name="VcsDirectoryMappings">
|
||||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
<mapping directory="" vcs="Git" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
@@ -3,7 +3,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = "ru.thiflict"
|
group = "ru.thiflict"
|
||||||
version = "1.0-SNAPSHOT"
|
version = "1.0.0"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
|||||||
@@ -8,22 +8,24 @@ package ru.thiflict
|
|||||||
* @author Thiflict
|
* @author Thiflict
|
||||||
*
|
*
|
||||||
* @since[1.0.0]
|
* @since[1.0.0]
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
object BinCheck {
|
object BinCheck {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Проверяет наличие единицы в заданом регистре
|
* Проверяет наличие единицы в заданом регистре
|
||||||
*
|
*
|
||||||
* Тип данных [Int]
|
* Тип данных для проверяемого числа [Short].
|
||||||
|
* Тип данных для проверяемого регистра [Byte]
|
||||||
*
|
*
|
||||||
* Пример:
|
* Пример:
|
||||||
* ```
|
* ```
|
||||||
* checkRegisterShort(0100, 2)
|
* checkRegisterShort(8, 3)
|
||||||
* ```
|
* ```
|
||||||
* @return true
|
* @return true
|
||||||
*/
|
*/
|
||||||
fun checkRegisterShort(input: Int, register: Int): Boolean {
|
fun checkRegisterShort(input: Short, register: Byte): Boolean {
|
||||||
val mask = 1 shl 2
|
val binaryString = String.format("%16s", input.toInt().toString(2).replace(' ', '0'))
|
||||||
|
val index = 15 - register.toInt()
|
||||||
|
return binaryString[index] == '1'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
38
src/test/kotlin/CheckRegisterTest.kt
Normal file
38
src/test/kotlin/CheckRegisterTest.kt
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import ru.thiflict.BinCheck.checkRegisterShort
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Тест [checkRegisterShort]
|
||||||
|
*
|
||||||
|
* Его писал Qwen3 Coder
|
||||||
|
*/
|
||||||
|
fun main() {
|
||||||
|
// Тест 1: Проверка значения 8 в регистре 3 (должно быть true)
|
||||||
|
println("Тест 1: checkRegisterShort(8, 3) = ${checkRegisterShort(8, 3.toByte())}")
|
||||||
|
|
||||||
|
// Тест 2: Проверка значения 16 в регистре 4 (должно быть true)
|
||||||
|
println("Тест 2: checkRegisterShort(16, 4) = ${checkRegisterShort(16, 4.toByte())}")
|
||||||
|
|
||||||
|
// Тест 3: Проверка значения 1 в регистре 0 (должно быть true)
|
||||||
|
println("Тест 3: checkRegisterShort(1, 0) = ${checkRegisterShort(1, 0.toByte())}")
|
||||||
|
|
||||||
|
// Тест 4: Проверка значения 0 в регистре 0 (должно быть false)
|
||||||
|
println("Тест 4: checkRegisterShort(0, 0) = ${checkRegisterShort(0, 0.toByte())}")
|
||||||
|
|
||||||
|
// Тест 5: Проверка значения 32767 в регистре 15 (должно быть false)
|
||||||
|
println("Тест 5: checkRegisterShort(32767, 15) = ${checkRegisterShort(32767, 15.toByte())}")
|
||||||
|
|
||||||
|
// Тест 6: Проверка значения 32767 в регистре 0 (должно быть true)
|
||||||
|
println("Тест 6: checkRegisterShort(32767, 0) = ${checkRegisterShort(32767, 0.toByte())}")
|
||||||
|
|
||||||
|
// Тест 7: Проверка значения 15 в регистре 3 (должно быть true)
|
||||||
|
println("Тест 7: checkRegisterShort(15, 3) = ${checkRegisterShort(15, 3.toByte())}")
|
||||||
|
|
||||||
|
// Тест 8: Проверка значения 15 в регистре 0 (должно быть true)
|
||||||
|
println("Тест 8: checkRegisterShort(15, 0) = ${checkRegisterShort(15, 0.toByte())}")
|
||||||
|
|
||||||
|
// Тест 9: Проверка значения 256 в регистре 8 (должно быть true)
|
||||||
|
println("Тест 9: checkRegisterShort(256, 8) = ${checkRegisterShort(256, 8.toByte())}")
|
||||||
|
|
||||||
|
// Тест 10: Проверка значения -1 в регистре 0 (должно быть true, так как все биты установлены)
|
||||||
|
println("Тест 10: checkRegisterShort(-1, 0) = ${checkRegisterShort(-1, 0.toByte())}")
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user