标签: assertion

当我在GSON上运行Proguard时使用应用程序崩溃(使用枚举)

我在我的Android应用程序中使用GSON来解析数据.我在我的Model对象中添加了一个枚举.添加枚举后,我的应用程序开始崩溃.当我创建runProguard时,一切正常.当程序成立时,我做了我在互联网上找到的所有解决问题的方法.但仍然没有运气.

我已经在proguard规则文件中做了以下事情

-keep class com.google.** { *; }

-keepattributes *Annotation*
-keepattributes Signature

-keepclassmembers enum * { public static **[] values(); public static ** valueOf(java.lang.String); }
Run Code Online (Sandbox Code Playgroud)

Enum Stuff示例:

public enum TypeX {
@SerializedName("live")
LIVE,

@SerializedName("upcoming")
UPCOMING,

@SerializedName("replay")
REPLAY; }
Run Code Online (Sandbox Code Playgroud)

我的堆栈跟踪

java.lang.AssertionError
        at com.google.gson.internal.bind.TypeAdapters$EnumTypeAdapter.<init>(Unknown Source)
        at com.google.gson.internal.bind.TypeAdapters$26.create(Unknown Source)
        at com.google.gson.Gson.getAdapter(Unknown Source)
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.<init>(Unknown Source)
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(Unknown Source)
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(Unknown Source)
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(Unknown Source)
        at com.google.gson.Gson.getAdapter(Unknown Source)
        at com.google.gson.internal.bind.CollectionTypeAdapterFactory.create(Unknown Source)
        at com.google.gson.Gson.getAdapter(Unknown Source)
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.<init>(Unknown Source)
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(Unknown Source)
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(Unknown …
Run Code Online (Sandbox Code Playgroud)

java android json gson assertion

10
推荐指数
1
解决办法
2750
查看次数

nose.tools.eq_ vs assertEqual

问题:

我们一直在使用nose测试运行器.

我不时会看到我们的测试有eq_()电话:

eq_(actual, expected)
Run Code Online (Sandbox Code Playgroud)

而不是共同的:

self.assertEqual(actual, expected)
Run Code Online (Sandbox Code Playgroud)

问题:

nose.tools.eq_与标准的单元测试框架相比,使用是否有任何好处assertEqual()?它们实际上相当吗?


思考:

好吧,对于一个,eq_更短,但必须从中导入nose.tools,使得测试依赖于测试运行器库,这可能使得更难以切换到不同的测试运行器,比如说py.test.在另一方面,我们也用@istest,@nottest以及@attr鼻子装饰了很多.

python testing nose assertion python-unittest

10
推荐指数
1
解决办法
4350
查看次数

如何通过WebDriver验证加载页面中的文本

我需要通过WebDriver验证页面中的文本.我喜欢将结果视为布尔值(true或false).可以通过提供WebDriver代码来帮助解决这个问题吗?

webdriver assertion selenium-webdriver

9
推荐指数
2
解决办法
9万
查看次数

如何解决 createState 函数的...返回旧的或无效的状态实例?

每当我在两个或多个表单之间滚动时,我都会不断收到此错误,当我更改此行时,错误就解决了:_SiteFormState createState() => state; 到 _SiteFormState createState() => 新 _SiteFormState; 但我想保留表单验证的状态,我怎样才能做到这一点?

这是我的代码:

  import 'dart:ui';
  import 'package:flutter/material.dart';
  import 'package:xperience/models/site.dart';
  import 'package:xperience/models/category.dart';
  import 'package:string_validator/string_validator.dart';

  typedef OnDelete();

  class SiteForm extends StatefulWidget {
  final ManageSiteModel site;
   _SiteFormState state = new _SiteFormState();
  final OnDelete onDelete;

   SiteForm({Key key, this.site, this.onDelete}) : super(key: key);
   @override
  _SiteFormState createState() => state;


  bool isValid() => state.validate();
  }

  class _SiteFormState extends State<SiteForm> {
   @override
  void dispose() {
   super.dispose();
  }


  @override
  void initState() {
  super.initState();
  }
  final form = new GlobalKey<FormState>();
  bool …
Run Code Online (Sandbox Code Playgroud)

validation widget assertion dart flutter

9
推荐指数
1
解决办法
1681
查看次数

Fluent Assertions 中的 Satisfy() 不适用于类对象集合

我有一堂课:

public class TestClass
{
    public int Id { get; set; }
    
    public int CampusId { get; set; }
    
    public int CurrentStudentCount { get; set; }
    
    public int MaxStudentCount { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

以及该类的对象集合:

var collection = new[]
    {
        new TestClass
        {
            Id = 55,
            CampusId = 38,
            CurrentStudentCount = 1,
            MaxStudentCount = 2
        },
        new TestClass
        {
            Id = 127,
            CampusId = 38,
            CurrentStudentCount = 2,
            MaxStudentCount = 2
        },
        new TestClass
        {
            Id = 126,
            CampusId = …
Run Code Online (Sandbox Code Playgroud)

c# assertion fluent-assertions

9
推荐指数
2
解决办法
6457
查看次数

Visual Studio regex_iterator Bug?

我在Visual Studio 2013上,我看到了我认为的错误,我希望有人可以证实?

string foo{ "A\nB\rC\n\r" };
vector<string> bar;

for (sregex_iterator i(foo.cbegin(), foo.cend(), regex("(.*)[\n\r]{1,2}")); i != sregex_iterator(); ++i){
    bar.push_back(i->operator[](1).str());
}
Run Code Online (Sandbox Code Playgroud)

此代码命中Visual Studio regex库中的Debug Assertion:

regex_iterator

如果我定义regex外部for-loop就可以了:

string foo{ "A\nB\rC\n\r" };
vector<string> bar;
regex bug("(.*)[\n\r]{1,2}");

for (sregex_iterator i(foo.cbegin(), foo.cend(), bug); i != sregex_iterator(); ++i){
    bar.push_back(i->operator[](1).str());
}
Run Code Online (Sandbox Code Playgroud)

或者,这可以在转换中正常工作,如此问题所示:

string foo{ "A\nB\rC\n\r" };
vector<string> bar;

// This puts {"A", "B", "C"} into bar
transform(sregex_iterator(foo.cbegin(), foo.cend(), regex("(.*)[\n\r]{1,2}")), sregex_iterator(), back_inserter(bar), [](const smatch& i){ return i[1].str(); });
Run Code Online (Sandbox Code Playgroud)

有人可以证实这是一个错误吗?

c++ regex assertion c++11 visual-studio-2013

8
推荐指数
1
解决办法
514
查看次数

Mat :: checkVector在OpenCV中做了什么?

我试图在OpenCV(C++)中使用以下函数

calcOpticalFlowPyrLK(prev_frame_gray, frame_gray, points[0], points[1], status, err, winSize, 3, termcrit, 0, 0.001);
Run Code Online (Sandbox Code Playgroud)

我收到这个错误

OpenCV Error: Assertion failed ((npoints = prevPtsMat.checkVector(2, CV_32F, true)) >= 0) in calcOpticalFlowPyrLK,
file /home/rohit/OpenCV_src/opencv-2.4.9/modules/video/src/lkpyramid.cpp, line 845
terminate called after throwing an instance of 'cv::Exception'
what():  /home/rohit/OpenCV_src/opencv-2.4.9/modules/video/src/lkpyramid.cpp:845:
error: (-215) (npoints = prevPtsMat.checkVector(2, CV_32F, true)) >= 0 in function calcOpticalFlowPyrLK
Run Code Online (Sandbox Code Playgroud)

以下两个都返回-1

frame_gray.checkVector(2, CV_32F, true)
prev_frame_gray.checkVector(2, CV_32F, true)
Run Code Online (Sandbox Code Playgroud)

我想知道checkVector实际上做了什么,因为它会导致断言错误,如上所示.

c++ opencv assertion mat

8
推荐指数
1
解决办法
6875
查看次数

countNonZero函数在openCV中给出一个断言错误

我尝试使用countNonZero()函数进行水平投影,如下所示.

Mat src = imread(INPUT_FILE, CV_LOAD_IMAGE_COLOR);
Mat binaryImage = src.clone();
cvtColor(src, src, CV_BGR2GRAY);

Mat horizontal = Mat::zeros(1,binaryImage.cols, CV_8UC1);

for (int i = 0; i<binaryImage.cols; i++)
{
    Mat roi = binaryImage(Rect(0, 0, 1, binaryImage.rows));

    horizontal.at<int>(0,i) = countNonZero(roi);
    cout << "Col no:" << i << " >>" << horizontal.at<int>(0, i);
}
Run Code Online (Sandbox Code Playgroud)

但是在调用countonZero()函数时出现错误.错误如下.

    OpenCV Error: Assertion failed (src.channels() == 1 && func != 0) in cv::countNo
    nZero, file C:\builds\2_4_PackSlave-win32-vc12-shared\opencv\modules\core\src\st
    at.cpp, line 549
Run Code Online (Sandbox Code Playgroud)

有人可以指出错误吗?

c++ opencv assertion projection-matrix

8
推荐指数
1
解决办法
1万
查看次数

如何创建未在故障跟踪中显示的自定义JUnit4断言

我想在我们的代码库中添加一些自定义断言,以正确隐藏故障跟踪.我知道如何编写一个可以静态导入的公共静态方法.我知道如何重用旧的断言或抛出新的断言AssertionError.

我无法弄清楚如何做的是将新的自定义断言保留在Failure Trace之外.我们已经习惯了故障跟踪中的第一个命中,而不是断言代码本身,而是调用断言的测试代码.

我知道有一个filtertrace控制过滤堆栈的属性,但我找不到任何关于将新断言添加到过滤器所需要做的好文档.

我想做的一个例子:

package testassertions;

import static newassertions.MyAssertions.myAssertTrue;

import org.junit.Test;

public class ExampleTest {
    @Test
    public void myAssertTruePassing() { myAssertTrue(true); }

    @Test
    public void myAssertTrueFailing() { myAssertTrue(false); }
}
Run Code Online (Sandbox Code Playgroud)
package newassertions;

import static org.junit.Assert.assertTrue;

public class MyAssertions {

    public static void myAssertTrue(boolean b) {
        assertTrue(b);
    }
}
Run Code Online (Sandbox Code Playgroud)

myAssertTrueFailing()的失败跟踪显示:

java.lang.AssertionError
    at newassertions.MyAssertions.myAssertTrue(MyAssertions.java:8)
    at testassertions.ExampleTest.myAssertTrueFailing(ExampleTest.java:12)
Run Code Online (Sandbox Code Playgroud)

我需要它只显示:

java.lang.AssertionError
    at testassertions.ExampleTest.myAssertTrueFailing(ExampleTest.java:12)
Run Code Online (Sandbox Code Playgroud)

java junit4 assertion java-5

8
推荐指数
1
解决办法
2525
查看次数

是否可以在 GCC/GNU C 中编写一个 _Static_assert 来验证编译时内存中位字段的布局?

假设我有以下定义:

#include <stdbool.h>
#include <stdint.h>
#define ASSERT(cond) _Static_assert(cond, #cond)

typedef union {
    struct {
        bool bit0:1;
        bool bit1:1;
        bool bit2:1;
        bool bit3:1;
        bool bit4:1;
        bool bit5:1;
        bool bit6:1;
        bool bit7:1;
    };
    uint8_t bits;
} byte;

ASSERT(sizeof(byte) == sizeof(uint8_t));
Run Code Online (Sandbox Code Playgroud)

能不能写个代码,比如

#include <assert.h>
// ...
    assert(((byte) { .bit0 = 1 }).bits == 0b00000001);
    assert(((byte) { .bit1 = 1 }).bits == 0b00000010);
    assert(((byte) { .bit2 = 1 }).bits == 0b00000100);
    assert(((byte) { .bit3 = 1 }).bits == 0b00001000);
    assert(((byte) { .bit4 = 1 …
Run Code Online (Sandbox Code Playgroud)

c gcc static-assert assertion bit-fields

8
推荐指数
1
解决办法
291
查看次数