From 14c793b8806e3f52e37f1ba68131ff691d3abdb8 Mon Sep 17 00:00:00 2001 From: thiflict <121az348@gmail.com> Date: Wed, 10 Jun 2026 11:35:55 +0500 Subject: [PATCH] =?UTF-8?q?=D0=91=D0=B0=D0=B3=D1=84=D0=B8=D0=BA=D1=81?= =?UTF-8?q?=D1=8B=20=D0=B8=20=D0=BC=D0=B5=D0=BB=D0=BA=D0=B8=D0=B5=20=D0=B4?= =?UTF-8?q?=D0=BE=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- readme.md | 4 ++-- src/main/kotlin/BinCheck.kt | 29 ++++++++++++++++++++++++++-- src/test/kotlin/CheckRegisterTest.kt | 7 +++++++ 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/readme.md b/readme.md index be4bfeb..d036fce 100644 --- a/readme.md +++ b/readme.md @@ -1,5 +1,5 @@ # BinaryUtils -пока пох на описание лмао +Детальная информация о проекте лежит в Wiki как импортировать в проект: @@ -12,6 +12,6 @@ repositories { dependencies { // Добавить в dependencies - implementation("ru.thiflict.binaryutils:binary-utils:1.0.0") + implementation("ru.thiflict.binaryutils:binary-utils:1.0.0") // У релизов всегда актуальная версия } ``` \ No newline at end of file diff --git a/src/main/kotlin/BinCheck.kt b/src/main/kotlin/BinCheck.kt index 63e3ccb..43b4203 100644 --- a/src/main/kotlin/BinCheck.kt +++ b/src/main/kotlin/BinCheck.kt @@ -17,14 +17,39 @@ object BinCheck { * Тип данных для проверяемого числа [Short]. * Тип данных для проверяемого регистра [Byte] * + * Регистр *не может быть* **отрицательным** или **больше 15** + * * Пример: * ``` * checkRegisterShort(8, 3) * ``` - * @return true + * @return [Boolean] + * @throws IllegalArgumentException */ - fun checkRegisterShort(input: Short, register: Byte): Boolean { + fun checkRegisterShort(input: Short, register: Byte, verbose: Boolean = false): Boolean { + // Защиты от дурачков + if (register < 0) throw IllegalArgumentException("Проверяемый регистр не может быть отрицательным!") + if (register > 15) throw IllegalArgumentException("Проверяемый регистр не может быть больше, чем количество регистров Short!") + + if (verbose) println("Debug: checkRegisterShort(): Выполнена проверка на IllegalArgumentException") + val binaryString = String.format("%16s", input.toInt().toString(2).replace(' ', '0')) + + if (verbose) println("Debug: checkRegisterShort(): ${ + if (binaryString.startsWith("-")) { + val binaryStringFormatted = binaryString + .drop(1) + .chunked(4) + .joinToString(" ") + "-$binaryStringFormatted" + } + else { + binaryString + .chunked(4) + .joinToString(" ") + } + }") + val index = 15 - register.toInt() return binaryString[index] == '1' } diff --git a/src/test/kotlin/CheckRegisterTest.kt b/src/test/kotlin/CheckRegisterTest.kt index 24f8330..54f5211 100644 --- a/src/test/kotlin/CheckRegisterTest.kt +++ b/src/test/kotlin/CheckRegisterTest.kt @@ -35,4 +35,11 @@ fun main() { // Тест 10: Проверка значения -1 в регистре 0 (должно быть true, так как все биты установлены) println("Тест 10: checkRegisterShort(-1, 0) = ${checkRegisterShort(-1, 0.toByte())}") + + // Тест на кидание IllegalArgumentException №1 +// println("Тест 11: checkRegisterShort(5, -1) = ${checkRegisterShort(5, (-1).toByte())}") + + // Тест на кидание IllegalArgumentException №2 +// println("Тест 11: checkRegisterShort(25, 16) = ${checkRegisterShort(32767.toShort(), 15.toByte(), true)}") + } \ No newline at end of file