mishin / presentation

мои презентации
Apache License 2.0
5 stars 1 forks source link

14 августа #13

Open mishin opened 1 year ago

mishin commented 1 year ago
mishin commented 1 year ago
package com.example.elastic;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class SolutionTest {

    @Test
    public void testDeleteMiddle() {
        // Test case 1: List with odd number of nodes
        ListNode head1 = new ListNode(1);
        head1.next = new ListNode(2);
        head1.next.next = new ListNode(3);
        head1.next.next.next = new ListNode(4);
        head1.next.next.next.next = new ListNode(5);

        Solution solution = new Solution();
        ListNode result1 = solution.deleteMiddle(head1);

        Assertions.assertEquals("1 -> 2 -> 4 -> 5 -> null", getListAsString(result1));

        // Test case 2: List with even number of nodes
        ListNode head2 = new ListNode(1);
        head2.next = new ListNode(2);
        head2.next.next = new ListNode(3);
        head2.next.next.next = new ListNode(4);

        ListNode result2 = solution.deleteMiddle(head2);

        Assertions.assertEquals("1 -> 2 -> 3 -> 4 -> null", getListAsString(result2));

        // Test case 3: List with only one node
        ListNode head3 = new ListNode(1);

        ListNode result3 = solution.deleteMiddle(head3);

        Assertions.assertNull(result3);

        // Test case 4: Empty list
        ListNode head4 = null;

        ListNode result4 = solution.deleteMiddle(head4);

        Assertions.assertNull(result4);
    }

    private String getListAsString(ListNode head) {
        StringBuilder sb = new StringBuilder();
        ListNode current = head;
        while (current != null) {
            sb.append(current.val);
            if (current.next != null) {
                sb.append(" -> ");
            }
            current = current.next;
        }
        sb.append(" -> null");
        return sb.toString();
    }
}
mishin commented 1 year ago

https://yandex.ru/maps/2/saint-petersburg/house/naberezhnaya_obvodnogo_kanala_165/Z0kYdQdlTkIGQFtjfXVxeH9iZA==/?ll=30.276564%2C59.927981&z=11.25

mishin commented 1 year ago

https://mail.flexcloud.ru/owa/#path=/calendar