0

我按照以下步骤创建我的项目

  1. 使用以下 dune 命令创建项目

    dune init proj --kind=lib mymaps

  2. 然后在“lib”目录下添加2个文件

我的地图.mli

type ('k, 'v) t
val empty : ('k, 'v) t
val insert : 'k -> 'v -> ('k, 'v) t -> ('k, 'v) t

我的地图.ml

type ('k, 'v) t = ('k * 'v) list
let rec insert k v m = match m with 
  | [] -> [(k, v)]
  | (eK, eV) :: tl -> let (nK, nV) = if (eK = k) then (k, v) else (eK, eV) in 
                    (nK, nV) :: insert k v tl
let empty = []
  1. 在“tests”目录下添加以下文件

mymaps_tests.ml

open Ounit2
open Mymaps
let empty_test = 
  "empty has no bindings" >:: (fun _ -> assert_equal [] (empty));
let mymap_tests = [empty_test]
let suite = "maps suite" >::: mymap_tests
let _ = run_test_tt_main suite

但是,当我去命令行并说它dune build

File "test/dune", line 2, characters 7-13:
2 |  (name mymaps))
       ^^^^^^
Error: Module "Mymaps" doesn't exist.     

这是我工作的 GitHub 链接https://github.com/abhsrivastava/mymaps

我正在关注 YouTube 上的教程,但我没有看到他们为测试项目实现任何模块,他们直接编写了测试。不知道为什么要寻找另一个正在测试的 Mymaps。

4

1 回答 1

0

我想我发现了这个问题。测试文件的名称应与项目的名称相同。我将测试文件重命名为“mymaps.ml”,然后错误就消失了。

于 2022-03-04T07:01:44.173 回答