Recommended unit testing setup
What is the recommended way to write and run unit tests in Ada? Which test library and test runner? Does Alire run the tests (alr test
does not seem to do it)?
1 post - 1 participant
What is the recommended way to write and run unit tests in Ada? Which test library and test runner? Does Alire run the tests (alr test
does not seem to do it)?
1 post - 1 participant
There's something about polymorphism in Ada that I don't understand. (Or maybe it's the package naming?) I'm trying to parse an XML file using xmlada
library and I followed the example I found in tests for this library that uses Debug_Reader
. Below is the problematic code:
-- cog_cli-xml.adb
with Ada.Strings.Unbounded;
with Sax.Readers;
with Input_Sources.Strings;
with Unicode.CES.Basic_8bit;
with Cog_Cli.Xml_Reader;
with Cog_Cli_Doc;
package body Cog_Cli.Xml is
package Asu renames Ada.Strings.Unbounded;
package Ccxr renames Cog_Cli.Xml_Reader;
package Sr renames Sax.Readers;
package Iss renames Input_Sources.Strings;
package Ccd renames Cog_Cli_Doc;
package U8bit renames Unicode.CES.Basic_8bit;
function Cli_Help (Command : String) return String is
Doc_Reader : Ccxr.Reader;
Input : Iss.String_Input;
Cli_Help : constant Ccd.Content_Type := Ccd.Get_Content ("cli.xml");
begin
Iss.Open (Cli_Help.Content.all,
Encoding => U8bit.Basic_8bit_Encoding,
Input => Input);
Ccxr.Set_Command (Doc_Reader, Command);
Sr.Set_Feature (Doc_Reader, Sr.Namespace_Prefixes_Feature, False);
Sr.Set_Feature (Doc_Reader, Sr.Namespace_Feature, False);
Sr.Set_Feature (Doc_Reader, Sr.Validation_Feature, False);
Sr.Parse (Doc_Reader, Input);
Iss.Close (Input);
return Asu.To_String (Doc_Reader.Help);
end Cli_Help;
end Cog_Cli.Xml;
-- cog_cli-xml_reader.ads
with Sax.Readers;
with Unicode.CES;
with Sax.Attributes;
with Ada.Strings.Unbounded;
package Cog_Cli.Xml_Reader is
package Asu renames Ada.Strings.Unbounded;
type Reader is new Sax.Readers.Reader with private;
procedure Start_Element
(Handler : in out Reader;
Namespace_URI : Unicode.CES.Byte_Sequence := "";
Local_Name : Unicode.CES.Byte_Sequence := "";
Qname : Unicode.CES.Byte_Sequence := "";
Atts : Sax.Attributes.Attributes'Class);
procedure End_Element
(Handler : in out Reader;
Namespace_URI : Unicode.CES.Byte_Sequence := "";
Local_Name : Unicode.CES.Byte_Sequence := "";
Qname : Unicode.CES.Byte_Sequence := "");
procedure Characters
(Handler : in out Reader;
Ch : Unicode.CES.Byte_Sequence);
procedure Set_Command (Handler : in out Reader; Command : String);
procedure Set_Help (Handler : in out Reader; Help : String);
private
type Reader is new Sax.Readers.Reader with record
Command : Asu.Unbounded_String;
Help : Asu.Unbounded_String;
end record;
end Cog_Cli.Xml_Reader;
with Ada.Text_IO;
with Ada.Strings.Unbounded;
package body Cog_Cli.Xml_Reader is
package Ati renames Ada.Text_IO;
package Asu renames with Ada.Strings.Unbounded;
procedure Start_Element
(Handler : in out Reader;
Namespace_URI : Unicode.CES.Byte_Sequence := "";
Local_Name : Unicode.CES.Byte_Sequence := "";
Qname : Unicode.CES.Byte_Sequence := "";
Atts : Sax.Attributes.Attributes'Class) is
begin
null;
end Start_Element;
procedure Characters
(Handler : in out Reader;
Ch : Unicode.CES.Byte_Sequence) is
begin
null;
end Characters;
procedure End_Element
(Handler : in out Reader;
Namespace_URI : Unicode.CES.Byte_Sequence := "";
Local_Name : Unicode.CES.Byte_Sequence := "";
Qname : Unicode.CES.Byte_Sequence := "") is
begin
null;
end End_Element;
procedure Set_Command (Handler : in out Reader; Command : String) is
begin
Handler.Command := Asu.To_Unbounded_String (Command);
end Set_Command;
procedure Set_Help (Handler : in out Reader; Help : String) is
begin
Handler.Help := Asu.To_Unbounded_String (Help);
end Set_Help;
end Cog_Cli.Xml_Reader;
The problem is that Sr.Set_Feature
doesn't believe that Doc_Reader
is the right type... I have no idea why. The literal error I'm getting is:
cog_cli-xml.adb:27:09: error: no candidate interpretations match the actuals:
cog_cli-xml.adb:27:23: error: expected private type "Readers.Reader" defined at sax-readers.ads:778
cog_cli-xml.adb:27:23: error: found private type "Xml_Reader.Reader" defined at cog_cli-xml_reader.ads:10
SweetAda (https://www.sweetada.org) got another step of functionality in the high-side of computing and successfully boots on an (QEMUβ’-emulated) PowerPC 64-bit POWER8 (R) platform.
The support is minimal, but it is able to startup from CPU reset and can do output on a terminal console.
Standby for future improvements.
1 post - 1 participant
RSS-Bridge tried to fetch a page on a website. But it doesn't exists.
#0 index.php(11): RssBridge->main()
#1 lib/RssBridge.php(113): DisplayAction->execute()
#2 actions/DisplayAction.php(71): DisplayAction->createResponse()
#3 actions/DisplayAction.php(106): YoutubeBridge->collectData()
#4 bridges/YoutubeBridge.php(198): YoutubeBridge->collectDataInternal()
#5 bridges/YoutubeBridge.php(111): YoutubeBridge->ytGetSimpleHTMLDOM()
#6 bridges/YoutubeBridge.php(465): getSimpleHTMLDOM()
#7 lib/contents.php(157): getContents()
#8 lib/contents.php(106)
No maintainer
Does anyone know what is going on with that news group? Seemingly thousands of spams are now appearing each day. I only watch that group (from Google groups web interface): is it that way for all unmoderated news groups these days?
π We have just published new vscode extension version 24.0.3 π with experimental Mac OS M1 π» native support! Don't hesitate sharing the feedback! Does it work for you? I hope
for Target use "aarch64-darwin";
isn't needed any more for native compiler (despite README says this). Also Linux ARM64 native support was added in 24.0.2, which wasn't published on Marketplace (but it's available on open vsx), so you can try it with remote mode is you have ARM64 server β¨.
24.0.2 and 24.0.3 have many other improvements. Happy coding! π¨
I am trying to calculate the square root of big numbers (around 16 digits) using the Big_Reals
package. I have the following square root function which uses the Newton-Raphson method
pragma Ada_2022;
with Ada.Numerics.Big_Numbers.Big_Reals;
use Ada.Numerics.Big_Numbers.Big_Reals;
function Big_Sqrt(X: Big_Real) return Big_Real is
package Converter is new Float_Conversions(Float);
use Converter;
Z: Big_Real := X;
Big_Half: Big_Real := To_Big_Real(0.5);
begin
for I in 1..32 loop
Z := Big_Half * (Z+X/Z);
Put_Line(Z'Image);
end loop;
return Z;
end Big_Sqrt;
The output with input 1813789079679324 is
906894539839662.500
453447269919832.249
226723634959918.124
113361817479963.062
56680908739989.531
28340454370010.765
14170227185037.382
raised STORAGE_ERROR : Ada.Numerics.Big_Numbers.Big_Integers.Bignums.Normalize: big integer limit exceeded
I'm assuming this happens because although the whole part of the number is getting smaller there is too much space being used for the decimal part but I can't find a way to reduce the precision of the decimal part.
Didnβt see a thread for this yet, so figured I would start one. Iβve only worked on part 1. I did like that I could come up with various methods of doing this right off the bat. I decided on spoiler.
5 posts - 3 participants
While working on day 6 of AoC, I found myself breaking a larger calculation into parts and saving them as constants in the declarative region of the function. This was super clean for reading and let me document all my steps nicely. I also knew that if any of the steps failed, then my result should be 0. So I figured I would put an exception handler in the function and return 0 (Note that the case where exceptions happen would be pretty rare based on some really edge case inputs that werenβt practical to the problem):
The problem I ran into is if the early steps raised an exception, then the exception handler wouldnβt catch them as they were in the declarative region. See mock up below:
function Calculate(Inputs : Input_Type) return Integer is
Step_1 : constant Integer := Some_Function(Stuff);
Step_2 : constant Integer := Some_Other_Function(Stuff);
begin
return Final_Function(Step_1, Step_2);
exception
when others => return 0; -- doesn't catch Step_1 or Step_2 exceptions!!!
end Calculate;
Any suggestions on a clean way to catch those declarative exceptions? I donβt like putting them in a declare block in the function body because that just indents everything needlessly. Currently I renamed my original function to old_name_unhandled and call it a new wrapper function named the original name, but that does feel kinda silly.
I was hoping there is an aspect or pragma maybe?
6 posts - 5 participants
Hi, this is my first post in /r/ada, so I hope I'm not breaking any etiquette. I've briefly dabbled in Ada many years ago (didn't try SPARK, sadly) but I'm currently mostly a Rust programmer.
Rust and Ada are the two current contenders for the title of being the "safest language" in the industry. Now, Rust has affine types and the borrow-checker, etc. Ada has constraint subtyping, SPARK, etc. so there are certainly differences. My intuition and experience with both leads me to believe that Rust and Ada don't actually have the same definition of "safe", but I can't put my finger on it.
Could someone (preferably someone with experience in both language) help me? In particular, I'd be very interested in seeing examples of specifications that can be implemented safely in Ada but not in Rust. I'm ok with any reasonable definition of safety.
Our Programming Languages professor told us that:
"In Ada, the return type of an overloaded function can be used to disambiguate calls (thus two overloaded functions can have the same parameters)"
So this implies that in Ada, we could do something like this:
function Func (Var : Integer) return Integer;
function Func (Var : Integer) return Float;
And then create different implementations of these two functions, therefore overloading them.
This does not make much sense to me, how can the return type alone be sufficient to distinguish between overloaded subprograms? How would we even go about deciding which one of these functions we meant to call when we do decide to use them?
Did my professor make a mistake?
@JeremyGrosser hasnβt posted on todayβs puzzle yet; I hope he wonβt mind if I do.
Thereβs always at least one puzzle with ginormous numbers, though I donβt recall their appearance in as early as Day 5!
The first speed bump I encountered is that gnat defaults (?) to 32-bit integers for Natural
, so my machine choked, though nearly 12 hours later I canβt remember whether it choked on the input proper or during the tracing. Very well, then: spoiler
Is 32-bits a fixed standard for Adaβs Natural
? Since 64-bit numbers are not uncommon in these puzzles (at least 2 or 3 puzzles will go there), should I by default define a numeric type and use that? (Isnβt that arguably the Ada way anyway? Iβve always wished the puzzle master would be more specific about the data we might encounter in these puzzles.)
The second speed bump is that solving Part 2 the natural, βbrute-forceβ way takes the computer while, and I mean a while. It is doable! It took my machine βonlyβ about 15 minutes. (Iβve paid for those gigahertz; might as well use them, right?)
So, while I was able to solve Part 2 via brute force β not usually possible when we start to see 6-digit numbers, let alone 9-digit ones! β I decided to spoiler.
My solution is here. Iβd be interested to know if anyone took a different approach.
17 posts - 5 participants
svd2ada generates volatile arrays.
e.g. IMR_MR_Field_Array
There are two other options that I believe will work easily with spark. The .Val Hal.UInt32 or a record of booleans with different names instead of the array.
The array makes for simpler code. So before I switch to the value. Could anyone suggest how the Spark compatibility error may be avoided. Editing the svds isnβt ideal but possible. A function or procedure local instantiation would be ideal. Any ideas?
IMR1.MR.Arr(Var) := True;
error: volatile object cannot appear in this context. Spark RM 7.1.3 (10).
Thanks
2 posts - 1 participant
I want to install Max! home automation SW from Dmitry to my Synology NAS. This SW uses GTK ADA and I want to be sure about some things.http://www.dmitry-kazakov.de/ada/max_home_automation.htm
My NAS is Synology DS215j with Marvel Armada CPU.
Is this the right repository to install GTKADA from?
https://www.adacore.com/download/more
Which platform should I use ? ARM ELF 32 bit for Linux?
How to proceed then? I never compiled from source...
I got stuck on silly parsing bugs in part 1 and am too tired for part 2 tonight. Looks like itβs gonna be spoiler
9 posts - 5 participants