From c9a57d6afac77b65152c1b7b32c0fa85317802ac Mon Sep 17 00:00:00 2001 From: "d.kapustin" Date: Wed, 27 Sep 2023 16:08:23 +0300 Subject: [PATCH] =?UTF-8?q?6.4.0.=20=D0=A1=D0=BB=D0=BE=D0=B2=D0=BE=20?= =?UTF-8?q?=D0=BD=D0=B0=D1=87=D0=B8=D0=BD=D0=B0=D0=B5=D1=82=D1=81=D1=8F=20?= =?UTF-8?q?=D1=81=20...;=20https://job4j.ru/profile/exercise/2/task-view/9?= =?UTF-8?q?9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ru/j4j/array/ArrayChar.java | 12 ++++++++++ src/test/java/ru/j4j/array/ArrayCharTest.java | 23 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 src/main/java/ru/j4j/array/ArrayChar.java create mode 100644 src/test/java/ru/j4j/array/ArrayCharTest.java diff --git a/src/main/java/ru/j4j/array/ArrayChar.java b/src/main/java/ru/j4j/array/ArrayChar.java new file mode 100644 index 0000000..1b80e74 --- /dev/null +++ b/src/main/java/ru/j4j/array/ArrayChar.java @@ -0,0 +1,12 @@ +package ru.j4j.array; + +public class ArrayChar { + public static boolean startsWith(char[] word, char[] pref) { + for (int i = 0; i < pref.length; i++) { + if (word[i] != pref[i]) { + return false; + } + } + return true; + } +} diff --git a/src/test/java/ru/j4j/array/ArrayCharTest.java b/src/test/java/ru/j4j/array/ArrayCharTest.java new file mode 100644 index 0000000..21aa6fe --- /dev/null +++ b/src/test/java/ru/j4j/array/ArrayCharTest.java @@ -0,0 +1,23 @@ +package ru.j4j.array; + +import static org.assertj.core.api.Assertions.*; + +import org.junit.jupiter.api.Test; + +public class ArrayCharTest { + @Test + public void whenStartWithPrefixThenTrue() { + char[] word = {'H', 'e', 'l', 'l', 'o'}; + char[] pref = {'H', 'e'}; + boolean result = ArrayChar.startsWith(word, pref); + assertThat(result).isTrue(); + } + + @Test + public void whenNotStartWithPrefixThenFalse() { + char[] word = {'H', 'e', 'l', 'l', 'o'}; + char[] pref = {'H', 'i'}; + boolean result = ArrayChar.startsWith(word, pref); + assertThat(result).isFalse(); + } +} \ No newline at end of file