Ver código fonte

Wikibase: Default 'null' to 0, not 1 [#792]

gnosygnu 4 anos atrás
pai
commit
72051f4ce9

+ 43 - 0
400_xowa/src/gplx/xowa/xtns/scribunto/libs/Scrib_lib_wikibase_srl_visitor_tst.java

@@ -0,0 +1,43 @@
+/*
+XOWA: the XOWA Offline Wiki Application
+Copyright (C) 2012-2017 gnosygnu@gmail.com
+
+XOWA is licensed under the terms of the General Public License (GPL) Version 3,
+or alternatively under the terms of the Apache License Version 2.0.
+
+You may use XOWA according to either of these licenses as is most appropriate
+for your project on a case-by-case basis.
+
+The terms of each license can be found in the source code repository:
+
+GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
+Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
+*/
+package gplx.xowa.xtns.scribunto.libs;
+
+import gplx.Bry_;
+import gplx.Double_;
+import gplx.Keyval;
+import gplx.core.tests.Gftest;
+import gplx.xowa.xtns.wbases.claims.enums.Wbase_claim_value_type_;
+import gplx.xowa.xtns.wbases.claims.itms.Wbase_claim_globecoordinate;
+import org.junit.Test;
+
+public class Scrib_lib_wikibase_srl_visitor_tst {
+	private final Scrib_lib_wikibase_srl_visitor_fxt fxt = new Scrib_lib_wikibase_srl_visitor_fxt();
+	@Test
+	public void Geo_null_precision() {
+		fxt.TestGeoPrecision(0, "null"); // 2020-09-03|ISSUE#:792|null precision should default to 0 not 1;PAGE:wd:Q168751
+	}
+}
+class Scrib_lib_wikibase_srl_visitor_fxt {
+	private final Scrib_lib_wikibase_srl_visitor visitor = new Scrib_lib_wikibase_srl_visitor();
+	public void TestGeoPrecision(double expd, String prc) {
+		String lat = "12";
+		String lng = "34";
+		visitor.Visit_globecoordinate(new Wbase_claim_globecoordinate(123, Wbase_claim_value_type_.Tid__value, Bry_.new_a7(lat), Bry_.new_a7(lng), null, Bry_.new_u8_safe(prc), null));
+		Keyval[] actl = visitor.Rv();
+		Keyval[] actlGeo = (Keyval[])actl[1].Val();
+		Gftest.Eq__double(expd, Double_.cast(actlGeo[4].Val()));
+	}
+}

+ 40 - 27
400_xowa/src/gplx/xowa/xtns/wbases/claims/itms/Wbase_claim_globecoordinate.java

@@ -1,6 +1,6 @@
 /*
 /*
 XOWA: the XOWA Offline Wiki Application
 XOWA: the XOWA Offline Wiki Application
-Copyright (C) 2012-2017 gnosygnu@gmail.com
+Copyright (C) 2012-2020 gnosygnu@gmail.com
 
 
 XOWA is licensed under the terms of the General Public License (GPL) Version 3,
 XOWA is licensed under the terms of the General Public License (GPL) Version 3,
 or alternatively under the terms of the Apache License Version 2.0.
 or alternatively under the terms of the Apache License Version 2.0.
@@ -13,29 +13,42 @@ The terms of each license can be found in the source code repository:
 GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
 GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
 Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
 Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
 */
 */
-package gplx.xowa.xtns.wbases.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
-import gplx.xowa.xtns.wbases.claims.enums.*;
-public class Wbase_claim_globecoordinate extends Wbase_claim_base {
-	public Wbase_claim_globecoordinate(int pid, byte snak_tid, byte[] lat, byte[] lng, byte[] alt, byte[] prc, byte[] glb) {super(pid, snak_tid);
-		this.lat = lat; this.lng = lng; this.alt = alt; this.prc = prc; this.glb = glb;
-	}
-	@Override public byte	Val_tid() {return Wbase_claim_type_.Tid__globecoordinate;}
-	public byte[]			Lat() {return lat;} private final    byte[] lat;
-	public byte[]			Lng() {return lng;} private final    byte[] lng;
-	public byte[]			Alt() {return alt;} private final    byte[] alt;
-	public byte[]			Prc() {return prc;} private final    byte[] prc;
-	public byte[]			Glb() {return glb;} private final    byte[] glb;
-	public byte[]			Glb_ttl() {return glb_ttl;} private byte[] glb_ttl;
-
-	public void Glb_ttl_(byte[] v) {glb_ttl = v;} 
-	public Decimal_adp Prc_as_num() {
-		if (prc_as_num == null)
-			prc_as_num = Bry_.Eq(prc, Object_.Bry__null) ? Decimal_adp_.One : Decimal_adp_.parse(String_.new_a7(prc));
-		return prc_as_num;
-	}	private Decimal_adp prc_as_num;
-
-	@Override public void Welcome(Wbase_claim_visitor visitor) {visitor.Visit_globecoordinate(this);}
-	@Override public String toString() {// TEST:
-		return String_.Concat_with_str("|", Wbase_claim_value_type_.Reg.Get_str_or_fail(this.Snak_tid()), Wbase_claim_type_.Reg.Get_str_or_fail(this.Val_tid()), String_.new_u8(lat), String_.new_u8(lng), String_.new_u8(alt), String_.new_u8(prc), String_.new_u8(glb));
-	}
-}
+package gplx.xowa.xtns.wbases.claims.itms;
+
+import gplx.Bry_;
+import gplx.Decimal_adp;
+import gplx.Decimal_adp_;
+import gplx.Object_;
+import gplx.String_;
+import gplx.xowa.xtns.wbases.claims.Wbase_claim_visitor;
+import gplx.xowa.xtns.wbases.claims.enums.Wbase_claim_type_;
+import gplx.xowa.xtns.wbases.claims.enums.Wbase_claim_value_type_;
+
+public class Wbase_claim_globecoordinate extends Wbase_claim_base {
+	public Wbase_claim_globecoordinate(int pid, byte snak_tid, byte[] lat, byte[] lng, byte[] alt, byte[] prc, byte[] glb) {
+		super(pid, snak_tid);
+		this.lat = lat; this.lng = lng; this.alt = alt; this.prc = prc; this.glb = glb;
+	}
+	@Override public byte Val_tid() {return Wbase_claim_type_.Tid__globecoordinate;}
+	public byte[] Lat() {return lat;} private final byte[] lat;
+	public byte[] Lng() {return lng;} private final byte[] lng;
+	public byte[] Alt() {return alt;} private final byte[] alt;
+	public byte[] Prc() {return prc;} private final byte[] prc;
+	public byte[] Glb() {return glb;} private final byte[] glb;
+	public byte[] Glb_ttl() {return glb_ttl;} private byte[] glb_ttl;
+
+	public void Glb_ttl_(byte[] v) {glb_ttl = v;} 
+	public Decimal_adp Prc_as_num() {
+		if (prc_as_num == null) {
+			prc_as_num = Bry_.Eq(prc, Object_.Bry__null)
+				? Decimal_adp_.Zero // 2020-09-03|ISSUE#:792|null precision should default to 0 not 1;PAGE:wd:Q168751
+				: Decimal_adp_.parse(String_.new_a7(prc));
+		}
+		return prc_as_num;
+	} private Decimal_adp prc_as_num;
+
+	@Override public void Welcome(Wbase_claim_visitor visitor) {visitor.Visit_globecoordinate(this);}
+	@Override public String toString() {// TEST:
+		return String_.Concat_with_str("|", Wbase_claim_value_type_.Reg.Get_str_or_fail(this.Snak_tid()), Wbase_claim_type_.Reg.Get_str_or_fail(this.Val_tid()), String_.new_u8(lat), String_.new_u8(lng), String_.new_u8(alt), String_.new_u8(prc), String_.new_u8(glb));
+	}
+}

+ 91 - 87
400_xowa/src/gplx/xowa/xtns/wbases/hwtrs/Wdata_visitor__html_wtr_tst.java

@@ -1,6 +1,6 @@
 /*
 /*
 XOWA: the XOWA Offline Wiki Application
 XOWA: the XOWA Offline Wiki Application
-Copyright (C) 2012-2017 gnosygnu@gmail.com
+Copyright (C) 2012-2020 gnosygnu@gmail.com
 
 
 XOWA is licensed under the terms of the General Public License (GPL) Version 3,
 XOWA is licensed under the terms of the General Public License (GPL) Version 3,
 or alternatively under the terms of the Apache License Version 2.0.
 or alternatively under the terms of the Apache License Version 2.0.
@@ -13,89 +13,93 @@ The terms of each license can be found in the source code repository:
 GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
 GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
 Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
 Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
 */
 */
-package gplx.xowa.xtns.wbases.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
-import org.junit.*;
-import gplx.langs.jsons.*; import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.claims.itms.times.*; import gplx.xowa.xtns.wbases.parsers.*; import gplx.xowa.apps.apis.xowa.html.*;
-public class Wdata_visitor__html_wtr_tst {
-	@Before public void init() {fxt.init();} private Wdata_hwtr_mgr_fxt fxt = new Wdata_hwtr_mgr_fxt();
-	@Test   public void Monolingualtext() {
-		fxt
-		.Test_claim_val
-		( fxt.Wdata_fxt().Make_claim_monolingual(1, "en", "Motto")
-		, "Motto [en]"
-		);
-	}
-	@Test   public void Time() {
-		fxt
-		.Test_claim_val
-		( fxt.Wdata_fxt().Make_claim_time(1, "2001-02-03 04:05:06", Wbase_date.Fmt_ymdhns)
-		, "4:05:06 3 Feb 2001"
-		);
-	}
-	@Test   public void Time__julian() {
-		fxt
-		.Test_claim_val
-		( fxt.Wdata_fxt().Make_claim_time(1, "2001-02-03 04:05:06", Bry_.Empty, Bry_.new_a7("http://www.wikidata.org/entity/Q1985786"))
-		, "4:05:06 3 Feb 2001"
-		);
-	}
-	@Test   public void Quantity_ubound_lbound() {
-		fxt
-		.Test_claim_val
-		( fxt.Wdata_fxt().Make_claim_quantity(1, "50", "", "60", "30")
-		, "30-60"
-		);
-	}
-	@Test   public void Quantity_same() {
-		fxt
-		.Test_claim_val
-		( fxt.Wdata_fxt().Make_claim_quantity(1, "50", "1", "60", "40")
-		, "50±10"
-		);
-	}
-	@Test   public void Quantity_frac() {
-		fxt
-		.Test_claim_val
-		( fxt.Wdata_fxt().Make_claim_quantity(1, "+0.1234", "1", "+0.1235", "+0.1233")
-		, "0.1234±0.0001"
-		);
-	}
-	@Test   public void Entity_qid() {
-		fxt
-		.Init_resolved_qid(1, "item_1")
-		.Test_claim_val
-		( fxt.Wdata_fxt().Make_claim_entity_qid(1, 1)
-		, "<a href='/wiki/Q1'>item_1</a>"
-		);
-	}
-	@Test   public void Entity_pid() {
-		fxt
-		.Init_resolved_pid(1, "item_1")
-		.Test_claim_val
-		( fxt.Wdata_fxt().Make_claim_entity_pid(1, 1)
-		, "<a href='/wiki/Property:P1'>item_1</a>"
-		);
-	}
-	@Test   public void Globecoordinate() {
-		fxt
-		.Init_resolved_qid(2, "Earth")
-		.Test_claim_val
-		( fxt.Wdata_fxt().Make_claim_geo(1, "51.5072222", "-0.1275", ".000027777", "123", "http://www.wikidata.org/entity/Q2")
-		, "0°7&#39;39&#34;S, 51°30&#39;26&#34;E (<a href='/wiki/Q2'>Earth</a>)"
-		);
-	}
-	@Test   public void Globecoordinate__globe__null() {
-		fxt
-		.Test_claim_val
-		( fxt.Wdata_fxt().Make_claim_geo(1, "51.5072222", "-0.1275", ".000027777", "null", "")
-		, "0°7&#39;39&#34;S, 51°30&#39;26&#34;E"
-		);
-	}
-	@Test   public void Globecoordinate__precision__0() {	// PURPOSE: 0 precision was causing divide by 0 error; PAGE:ru.w:Лысково_(Калужская_область) DATE:2016-11-24
-		fxt
-		.Test_claim_val
-		( fxt.Wdata_fxt().Make_claim_geo(1, "51.5072222", "-0.1275", "0", "null", "")
-		, "0°6&#39;S, 51°30&#39;E"
-		);
-	}
-}
+package gplx.xowa.xtns.wbases.hwtrs;
+
+import gplx.Bry_;
+import gplx.xowa.xtns.wbases.claims.itms.times.Wbase_date;
+import org.junit.Before;
+import org.junit.Test;
+
+public class Wdata_visitor__html_wtr_tst {
+	@Before public void init() {fxt.init();} private Wdata_hwtr_mgr_fxt fxt = new Wdata_hwtr_mgr_fxt();
+	@Test   public void Monolingualtext() {
+		fxt
+		.Test_claim_val
+		( fxt.Wdata_fxt().Make_claim_monolingual(1, "en", "Motto")
+		, "Motto [en]"
+		);
+	}
+	@Test   public void Time() {
+		fxt
+		.Test_claim_val
+		( fxt.Wdata_fxt().Make_claim_time(1, "2001-02-03 04:05:06", Wbase_date.Fmt_ymdhns)
+		, "4:05:06 3 Feb 2001"
+		);
+	}
+	@Test   public void Time__julian() {
+		fxt
+		.Test_claim_val
+		( fxt.Wdata_fxt().Make_claim_time(1, "2001-02-03 04:05:06", Bry_.Empty, Bry_.new_a7("http://www.wikidata.org/entity/Q1985786"))
+		, "4:05:06 3 Feb 2001"
+		);
+	}
+	@Test   public void Quantity_ubound_lbound() {
+		fxt
+		.Test_claim_val
+		( fxt.Wdata_fxt().Make_claim_quantity(1, "50", "", "60", "30")
+		, "30-60"
+		);
+	}
+	@Test   public void Quantity_same() {
+		fxt
+		.Test_claim_val
+		( fxt.Wdata_fxt().Make_claim_quantity(1, "50", "1", "60", "40")
+		, "50±10"
+		);
+	}
+	@Test   public void Quantity_frac() {
+		fxt
+		.Test_claim_val
+		( fxt.Wdata_fxt().Make_claim_quantity(1, "+0.1234", "1", "+0.1235", "+0.1233")
+		, "0.1234±0.0001"
+		);
+	}
+	@Test   public void Entity_qid() {
+		fxt
+		.Init_resolved_qid(1, "item_1")
+		.Test_claim_val
+		( fxt.Wdata_fxt().Make_claim_entity_qid(1, 1)
+		, "<a href='/wiki/Q1'>item_1</a>"
+		);
+	}
+	@Test   public void Entity_pid() {
+		fxt
+		.Init_resolved_pid(1, "item_1")
+		.Test_claim_val
+		( fxt.Wdata_fxt().Make_claim_entity_pid(1, 1)
+		, "<a href='/wiki/Property:P1'>item_1</a>"
+		);
+	}
+	@Test   public void Globecoordinate() {
+		fxt
+		.Init_resolved_qid(2, "Earth")
+		.Test_claim_val
+		( fxt.Wdata_fxt().Make_claim_geo(1, "51.5072222", "-0.1275", ".000027777", "123", "http://www.wikidata.org/entity/Q2")
+		, "0°7&#39;39&#34;S, 51°30&#39;26&#34;E (<a href='/wiki/Q2'>Earth</a>)"
+		);
+	}
+	@Test   public void Globecoordinate__globe__null() {
+		fxt
+		.Test_claim_val
+		( fxt.Wdata_fxt().Make_claim_geo(1, "51.5072222", "-0.1275", ".000027777", "null", "")
+		, "0°7&#39;39&#34;S, 51°30&#39;26&#34;E"
+		);
+	}
+	@Test   public void Globecoordinate__precision__0() {	// PURPOSE: 0 precision was causing divide by 0 error; PAGE:ru.w:Лысково_(Калужская_область) DATE:2016-11-24
+		fxt
+		.Test_claim_val
+		( fxt.Wdata_fxt().Make_claim_geo(1, "51.5072222", "-0.1275", "0", "null", "")
+		, "0°6&#39;S, 51°30&#39;E"
+		);
+	}
+}