首页 \ 问答 \ 数据流覆盖范围(Data Flow Coverage)

数据流覆盖范围(Data Flow Coverage)

如果您编写程序,通常可以驱动程序以覆盖所有路径。 因此,100%的覆盖率很容易获得(忽略现代编译器无法捕获的不可行的代码路径)。

但是,100%的代码覆盖率应该意味着所有变量定义使用覆盖率也都会实现,因为变量是在程序中定义的并在其中使用。 如果涵盖所有代码,则还应涵盖所有DU对。

那么,为什么它说路径覆盖更容易获得,但数据流覆盖通常不可能达到100%? 我不明白为什么不呢? 有什么例子呢?


If you write a program, it is usually possible to drive it such that all paths are covered. Hence, 100% coverage is easy to obtain (ignoring unfeasible code paths which modern compilers catch anyways).

However, 100% code coverage should imply that all variable definition-use coverage is also achieved, because variables are defined within the program and used within it. If all code is covered, all DU pairs should also be covered.

Why then, is it said that path coverage is easier to obtain, but data flow coverage is not usually possible to achieve 100% ? I do not understand why not? What can be an example of that?


原文:https://stackoverflow.com/questions/19884711
更新时间:2022-05-16 09:05

最满意答案

当您实际只需要一个字典时,您当前正在将其反序列化为字典列表。

可能有一种更简洁的方法,但您可以将其反序列化为键值对列表,然后将其转换为字典。 示例代码:

using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;

public class Test
{
    static void Main()
    {
        string json = "[{'Key':'x','Value':'y'},{'Key':'a','Value':'b'}]";

        var dictionary = JsonConvert.DeserializeObject<List<KeyValuePair<string, string>>>(json)
            .ToDictionary(pair => pair.Key, pair => pair.Value);

        Console.WriteLine(dictionary["x"]); // y
        Console.WriteLine(dictionary["a"]); // b
    }
}

You're currently deserializing it as a list of dictionaries, when you only actually want a single dictionary.

There may be a cleaner way of doing this, but you can deserialize it as a list of key-value pairs, then convert that into a dictionary. Sample code:

using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;

public class Test
{
    static void Main()
    {
        string json = "[{'Key':'x','Value':'y'},{'Key':'a','Value':'b'}]";

        var dictionary = JsonConvert.DeserializeObject<List<KeyValuePair<string, string>>>(json)
            .ToDictionary(pair => pair.Key, pair => pair.Value);

        Console.WriteLine(dictionary["x"]); // y
        Console.WriteLine(dictionary["a"]); // b
    }
}

相关问答

更多
  • 所以答案结果是编译器更好地了解所涉及的类型。 省略说明者使它工作,虽然为什么我的说法者错了我还没有得到。 var ret = rs.OfType() .Where(x => x.Key.ToString().StartsWith("Title")) .ToDictionary( k => k.Value.ToString(), v => rs.OfType() .Where(x => x.Key.ToSt ...
  • 解决这个问题的一种方法是为基于字典的类使用定制的JsonConverter 。 代码实际上非常简单。 public class CustomDictionaryConverter : JsonConverter { private string KeyPropertyName { get; set; } private string ValuePropertyName { get; set; } public CustomDictionaryConverter(stri ...
  • 你有一个多嵌套字典。 尝试: for i in oxford_dict["results"]: for j in i["lexicalEntries"]: for k in j["entries"]: for v in k["senses"]: print(v["definitions"]) 输出: ['a playing card with a single spot on it, ranked as the highest ...
  • 使用Json.NET和JsonConvert http://james.newtonking.com/projects/json/help/SerializingJSON.html 没关系字典或对象是序列化到Json Use Json.NET and JsonConvert http://james.newtonking.com/projects/json/help/SerializingJSON.html It doesn't matter dictionary or object are seriali ...
  • 这可以通过一点递归来完成。 我将把IsJson定义为学术演习。 :) Dictionary RecursiveDeserialize(string json) { var result = JsonConvert.DeserializeObject>(json); foreach (var pair in result.ToArray()) { if(IsJson(pair. ...
  • 这个JSON似乎没有描述字典。 相反,它似乎描述了一个包含一个字典的字典列表,其键是“CRMNextFields”,其值是另一个字典列表。 因此,反序列化到这个工作: var data = JsonConvert .DeserializeObject>>>> (/*your json*/); 并访问内部词典,如下所示: var crmFields = data.First()["CRMNextFi ...
  • 我认为你所寻找的是一种序列化关系的方法。 看一下: https://code.google.com/p/wadofstuff/wiki/DjangoFullSerializers#Relations 另请注意,自Django 1.5起,simplejson已弃用: https://code.djangoproject.com/ticket/18023#comment:10 我创建了一个版本的Wad of stuff序列化程序,它与Django 1.5一起使用: https://github.com/kolb ...
  • 您可以使用JavaScriptSerializer在json和Search类之间进行序列化/反序列化。 You can use JavaScriptSerializer to serialize/deserialize between json and your Search class.
  • 当您实际只需要一个字典时,您当前正在将其反序列化为字典列表。 可能有一种更简洁的方法,但您可以将其反序列化为键值对列表,然后将其转换为字典。 示例代码: using System; using System.Collections.Generic; using System.Linq; using Newtonsoft.Json; public class Test { static void Main() { string json = "[{'Key':'x','Val ...
  • 我认为你得到一个空结果的主要原因是因为你返回的是Result ,而不是你填充的dictionary变量。 另外,如果collListItem是IEnumerable (因为它似乎是,因为你用foreach循环它),你不需要逐项构建字典。 尝试: Dictionary dictionary=collListItem.ToDictionary(c=>c["ID"],c=>c["Title"]); return Json(dictionary,JsonReque ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。