gpt4 book ai didi

java - Google Java格式+验证Google Java格式组合无效

转载 作者:行者123 更新时间:2023-12-03 05:23:41 25 4
gpt4 key购买 nike

我是新来的。我只是将其添加到main repository中以查看其工作原理。这是我的build.gradle文件的样子:

plugins {
id 'java'

id 'application'

id 'com.github.sherter.google-java-format' version '0.8'
}

repositories {
jcenter()
}

dependencies {
compile fileTree(include: ['jblas-1.2.4.jar'], dir: 'libs')

implementation 'com.google.guava:guava:28.1-jre'

testImplementation 'junit:junit:4.12'
}

application {
mainClassName = 'sorting.bubblesort.BubbleSort'
}
如您所见,我应用了一个名为 google-java-format的插件。但是,我遇到了两个任务的问题:
googleJavaFormat
verifyGoogleJavaFormat
我可以运行 googleJavaFormat,它说它运行成功。但是,此后, verifyGoogleJavaFormat说它的格式不正确。这是唯一显然格式不正确的文件:
package DataStructures.MinPriorityQueue;

import datastructures.minpriorityqueue.MinHeap.MinHeap;
import org.junit.Test;

import java.util.Arrays;
import java.util.HashSet;
import java.util.PriorityQueue;

import static org.junit.Assert.*;

public class MinHeapTest {
@Test
public void containsTest() {
for (int i = 0; i < 10000; i++) {
HashSet<Integer> set = new HashSet<>();
MinHeap<Integer> heap = new MinHeap<>(Integer::compare);
for (int j = 0; j < 1000; j++)
if (Math.random() >= 0.5) {
set.add(j);
heap.add(j);
}
for (Integer integer : set) assertTrue(heap.contains(integer));
}
}

@Test
public void isEmptyTest() {
for (int i = 0; i < 100; i++) {
MinHeap<Integer> heap = new MinHeap<>(Integer::compare);
assertTrue(heap.isEmpty());
int randomAmount = 1 + (int) (Math.random() * 1000);
for (int j = 0; j < randomAmount; j++) heap.add((int) (Math.random() * 1000));
assertFalse(heap.isEmpty());
}
}

@Test
public void extractMinTest() {
for (int i = 0; i < 1000; i++) {
PriorityQueue<Integer> priorityQueue = new PriorityQueue<>(Integer::compare);
MinHeap<Integer> heap = new MinHeap<>(Integer::compare);
for (int j = 0; j < 1000; j++)
if (Math.random() >= 0.5) {
priorityQueue.add(j);
heap.add(j);
}
assertEquals(priorityQueue.poll(), heap.extractMin());
}
}

@Test
public void chainedExtractMinTest() {
for (int i = 0; i < 1000; i++) {
int[] toAdd = new int[1000];
MinHeap<Integer> heap = new MinHeap<>(Integer::compare);
for (int j = 0; j < toAdd.length; j++) {
toAdd[j] = (int) (Math.random() * 1000);
heap.add(toAdd[j]);
}
int[] sorted = toAdd.clone();
Arrays.sort(sorted);
int[] heapValues = new int[1000];
for (int j = 0; j < heapValues.length; j++) heapValues[j] = heap.extractMin();
assertArrayEquals(sorted, heapValues);
}
}

@Test
public void decreaseKeyTest() {
for (int i = 0; i < 1000; i++) {
MinHeap<Integer> heap = new MinHeap<>(Integer::compare);
PriorityQueue<Integer> queue = new PriorityQueue<>(Integer::compare);
for (int j = 0; j < 1000; j++) heap.add(j);
for (Integer j : heap) heap.decreaseValue(j, (int) (Math.random() * j));
for (Integer j : heap) queue.add(j);
while (!heap.isEmpty()) assertEquals(queue.poll(), heap.extractMin());
}
}
}
即使在此文件上运行 googleJavaFormat后, verifyGoogleJavaFormat也不会成功。为什么会这样呢?

最佳答案

好的,我知道了。由于我使用的是Intellij,它会在导入过程中移动。例如,每当在导入中看到星号*时,它都会对其进行扩展。我刚打开文件|设置|编辑器一般|自动导入并取消选中动态优化导入。

关于java - Google Java格式+验证Google Java格式组合无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62490331/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com