cats | REST API Fuzzer and negative testing tool

 by   Endava Java Version: cats-8.4.1 License: Apache-2.0

kandi X-RAY | cats Summary

cats is a Java library typically used in Testing, Swagger applications. cats has no bugs, it has no vulnerabilities, it has build file available, it has a Permissive License and it has medium support. You can download it from GitHub.
By using a simple and minimal syntax, with a flat learning curve, CATS (Contract Auto-generated Tests for Swagger) enables you to generate thousands of API tests within minutes with no coding effort. All tests are generated, run and reported automatically based on a pre-defined set of 87 Fuzzers. The Fuzzers cover a wide range of input data from fully random large Unicode values to well crafted, context dependant values based on the request data types and constraints. Even more, you can leverage the fact that CATS generates request payloads dynamically and write simple end-to-end functional tests.
    Support
      Quality
        Security
          License
            Reuse
            Support
              Quality
                Security
                  License
                    Reuse

                      kandi-support Support

                        summary
                        cats has a medium active ecosystem.
                        summary
                        It has 923 star(s) with 59 fork(s). There are 8 watchers for this library.
                        summary
                        There were 6 major release(s) in the last 6 months.
                        summary
                        There are 4 open issues and 47 have been closed. On average issues are closed in 15 days. There are no pull requests.
                        summary
                        It has a neutral sentiment in the developer community.
                        summary
                        The latest version of cats is cats-8.4.1
                        cats Support
                          Best in #Java
                            Average in #Java
                            cats Support
                              Best in #Java
                                Average in #Java

                                  kandi-Quality Quality

                                    summary
                                    cats has 0 bugs and 0 code smells.
                                    cats Quality
                                      Best in #Java
                                        Average in #Java
                                        cats Quality
                                          Best in #Java
                                            Average in #Java

                                              kandi-Security Security

                                                summary
                                                cats has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
                                                summary
                                                cats code analysis shows 0 unresolved vulnerabilities.
                                                summary
                                                There are 0 security hotspots that need review.
                                                cats Security
                                                  Best in #Java
                                                    Average in #Java
                                                    cats Security
                                                      Best in #Java
                                                        Average in #Java

                                                          kandi-License License

                                                            summary
                                                            cats is licensed under the Apache-2.0 License. This license is Permissive.
                                                            summary
                                                            Permissive licenses have the least restrictions, and you can use them in most projects.
                                                            cats License
                                                              Best in #Java
                                                                Average in #Java
                                                                cats License
                                                                  Best in #Java
                                                                    Average in #Java

                                                                      kandi-Reuse Reuse

                                                                        summary
                                                                        cats releases are available to install and integrate.
                                                                        summary
                                                                        Build file is available. You can build the component from source.
                                                                        summary
                                                                        Installation instructions, examples and code snippets are available.
                                                                        summary
                                                                        It has 20149 lines of code, 1919 functions and 386 files.
                                                                        summary
                                                                        It has medium code complexity. Code complexity directly impacts maintainability of the code.
                                                                        cats Reuse
                                                                          Best in #Java
                                                                            Average in #Java
                                                                            cats Reuse
                                                                              Best in #Java
                                                                                Average in #Java
                                                                                  Top functions reviewed by kandi - BETA
                                                                                  kandi has reviewed cats and discovered the below as its top functions. This is intended to give you an instant insight into cats implemented functionality, and help decide if they suit your requirements.
                                                                                  • Performs a custom test
                                                                                    • Check verify parameters and report result
                                                                                    • Sets the output variables
                                                                                    • Gets the value of the property in body
                                                                                  • Start the downloader
                                                                                    • Downloads a file from the given URL
                                                                                  • Runs the test case
                                                                                    • Check for missing fields
                                                                                  • Processes the fuzzing data
                                                                                    • Checks if the field value matches the fuzzy pattern
                                                                                  • Fuzzify the headers
                                                                                  • Performs a subset of the given fields and checks if required
                                                                                  • Performs the actual fuzzing
                                                                                  • Checks if the current path contains versioning information
                                                                                  • Runs the catcher
                                                                                  • Gets the fuzzing strategy
                                                                                  • Run test case
                                                                                  • Adds references to a schema
                                                                                  • Generate value
                                                                                  • fuzzing the given path
                                                                                  • Checks if the current path contains the required tags
                                                                                  • Parses the given SPEL expression
                                                                                  • Intercepts method invocation
                                                                                  • Do fuzzing
                                                                                  • Generates the boundary value
                                                                                  • Process the fuzzing data
                                                                                  Get all kandi verified functions for this library.
                                                                                  Get all kandi verified functions for this library.

                                                                                  cats Key Features

                                                                                  CATS is a REST API Fuzzer and negative testing tool for OpenAPI endpoints. CATS automatically generates, runs and reports tests with minimum configuration and no coding effort. Tests are self-healing and do not require maintenance.

                                                                                  cats Examples and Code Snippets

                                                                                  No Code Snippets are available at this moment for cats.
                                                                                  Community Discussions

                                                                                  Trending Discussions on cats

                                                                                  How to convince GHC about type equality on a recursive type
                                                                                  chevron right
                                                                                  Creating new columns based on data in row separated by specific character in R
                                                                                  chevron right
                                                                                  Doobie - lifting arbitrary effect into ConnectionIO CE3
                                                                                  chevron right
                                                                                  Extract data frames from nested list
                                                                                  chevron right
                                                                                  How do I implement two methods from two interfaces with the same name?
                                                                                  chevron right
                                                                                  Replace NA in DataFrame for multiple columns with mean per country
                                                                                  chevron right
                                                                                  Testing a NestJS Service that uses Prisma without actually accessing the database
                                                                                  chevron right
                                                                                  How to make smoother borders using Fragment shader in OpenGL?
                                                                                  chevron right
                                                                                  How to implement horizontal scrolling of tiles in MUI GridList?
                                                                                  chevron right
                                                                                  Cats auto derived with Seq
                                                                                  chevron right

                                                                                  QUESTION

                                                                                  How to convince GHC about type equality on a recursive type
                                                                                  Asked 2022-Apr-10 at 18:45

                                                                                  I'm defining a type whose type parameters have some relations. I have Item type which takes Cat and SubCat, but you can use some of the types of SubCat depending on Cat. For example, when you specify Cat1 as Cat, you can specify SubCat1 or SubCat2 as SubCat.

                                                                                  I implemented it using ValidSubCats type family to define valid SubCats for each Cat, and OneOf type family to define a constraint.

                                                                                  {-# LANGUAGE DataKinds, GADTs, PolyKinds, StandaloneKindSignatures, TypeFamilies, TypeOperators #-}
                                                                                  
                                                                                  import Data.Kind (Constraint, Type)
                                                                                  import Data.Type.Equality ((:~:)(..), TestEquality(..))
                                                                                  import Unsafe.Coerce (unsafeCoerce)
                                                                                  
                                                                                  data Cat = Cat1 | Cat2
                                                                                  type SCat :: Cat -> Type
                                                                                  data SCat cat where
                                                                                      SCat1 :: SCat 'Cat1
                                                                                      SCat2 :: SCat 'Cat2
                                                                                  
                                                                                  data SubCat = SubCat1 | SubCat2 | SubCat3
                                                                                  type SSubCat :: SubCat -> Type
                                                                                  data SSubCat subCat where
                                                                                      SSubCat1 :: SSubCat 'SubCat1
                                                                                      SSubCat2 :: SSubCat 'SubCat2
                                                                                      SSubCat3 :: SSubCat 'SubCat3
                                                                                  
                                                                                  type ValidSubCats :: Cat -> [SubCat]
                                                                                  type family ValidSubCats cat where
                                                                                      ValidSubCats 'Cat1 = '[ 'SubCat1, 'SubCat2 ]
                                                                                      ValidSubCats 'Cat2 = '[ 'SubCat2, 'SubCat3 ]
                                                                                  
                                                                                  type OneOf :: k -> [k] -> Constraint
                                                                                  type family OneOf t ts where
                                                                                      OneOf t (t ': _) = ()
                                                                                      OneOf t (_ ': ts) = OneOf t ts
                                                                                      OneOf _ _ = ('True ~ 'False)
                                                                                  
                                                                                  type Item :: Cat -> SubCat -> Type
                                                                                  data Item cat subCat where
                                                                                      Item :: OneOf subCat (ValidSubCats cat) => Item cat subCat
                                                                                  

                                                                                  Now, I'm trying to define a function to create an Item from SCat and SSubCat.

                                                                                  type HL :: (k -> Type) -> [k] -> Type
                                                                                  data HL f t where
                                                                                      HCons :: f t -> HL f ts -> HL f (t ': ts)
                                                                                      HNil :: HL f '[]
                                                                                  infixr 5 `HCons`
                                                                                  
                                                                                  validSSubCats :: SCat cat -> HL SSubCat (ValidSubCats cat)
                                                                                  validSSubCats SCat1 = SSubCat1 `HCons` SSubCat2 `HCons` HNil
                                                                                  validSSubCats SCat2 = SSubCat2 `HCons` SSubCat3 `HCons` HNil
                                                                                  
                                                                                  instance TestEquality SSubCat where
                                                                                      testEquality SSubCat1 SSubCat1 = Just Refl
                                                                                      testEquality SSubCat2 SSubCat2 = Just Refl
                                                                                      testEquality SSubCat3 SSubCat3 = Just Refl
                                                                                      testEquality _ _ = Nothing
                                                                                  
                                                                                  oneOf :: TestEquality f => f t -> HL f ts -> Maybe (OneOf t ts :~: (() :: Constraint))
                                                                                  oneOf x (HCons y ys) = case testEquality x y of
                                                                                                             Just Refl -> Just Refl
                                                                                                             Nothing -> unsafeCoerce $ oneOf x ys
                                                                                  oneOf _ HNil = Nothing
                                                                                  
                                                                                  makeItem :: SCat cat -> SSubCat subCat -> Maybe (Item cat subCat)
                                                                                  makeItem sCat sSubCat = case oneOf sSubCat (validSSubCats sCat) of
                                                                                                              Just Refl -> Just Item
                                                                                                              Nothing -> Nothing
                                                                                  

                                                                                  But as you can see, I'm using unsafeCoerce to define oneOf. I got this error when I removed it.

                                                                                  test.hs:54:39: error:
                                                                                      • Could not deduce: OneOf t ts1 ~ OneOf t (t1 : ts1)
                                                                                        from the context: ts ~ (t1 : ts1)
                                                                                          bound by a pattern with constructor:
                                                                                                     HCons :: forall {k} (f :: k -> *) (t :: k) (ts :: [k]).
                                                                                                              f t -> HL f ts -> HL f (t : ts),
                                                                                                   in an equation for ‘oneOf’
                                                                                          at q.hs:52:10-19
                                                                                        Expected: Maybe (OneOf t ts :~: (() :: Constraint))
                                                                                          Actual: Maybe (OneOf t ts1 :~: (() :: Constraint))
                                                                                        NB: ‘OneOf’ is a non-injective type family
                                                                                      • In the expression: oneOf x ys
                                                                                        In a case alternative: Nothing -> oneOf x ys
                                                                                        In the expression:
                                                                                          case testEquality x y of
                                                                                            Just Refl -> Just Refl
                                                                                            Nothing -> oneOf x ys
                                                                                      • Relevant bindings include
                                                                                          ys :: HL f ts1 (bound at q.hs:52:18)
                                                                                          y :: f t1 (bound at q.hs:52:16)
                                                                                          x :: f t (bound at q.hs:52:7)
                                                                                          oneOf :: f t
                                                                                                   -> HL f ts -> Maybe (OneOf t ts :~: (() :: Constraint))
                                                                                            (bound at q.hs:52:1)
                                                                                     |
                                                                                  54 |                            Nothing -> oneOf x ys
                                                                                     |                                       ^^^^^^^^^^
                                                                                  

                                                                                  How can I convince GHC that it can infer OneOf t (t ': ts) :~: (() :: Constraint) from OneOf t ts :~: (() :: Constraint) without using unsafeCoerce?

                                                                                  ANSWER

                                                                                  Answered 2022-Apr-10 at 18:45

                                                                                  I would suggest using something which has a value-level representation, since we can directly manipulate such things more easily. This is often easier to work with in general. For example:

                                                                                  data OneOf' t ts where
                                                                                    Here :: forall t ts. OneOf' t (t ': ts)
                                                                                    There :: forall t t2 ts. OneOf' t ts -> OneOf' t (t2 ': ts)
                                                                                  
                                                                                  oneOf' :: TestEquality f => f t -> HL f ts -> Maybe (OneOf' t ts)
                                                                                  oneOf' _ HNil = Nothing
                                                                                  oneOf' x (HCons y ys) =
                                                                                    case testEquality x y of
                                                                                      Just Refl -> Just Here
                                                                                      Nothing -> There <$> oneOf' x ys
                                                                                  

                                                                                  This does not directly answer the question as asked, although if you can write a function with type

                                                                                  convertOneOf :: forall t ts. OneOf' t ts -> (OneOf t ts :~: (() :: Constraint))
                                                                                  

                                                                                  then it would answer the exact question. Right now, I'm not sure how to do this (or even whether it is possible). I think you need an auxiliary function

                                                                                  weakenOneOf :: forall t t2 ts. OneOfTrue t ts -> OneOfTrue t (t2 ': ts)
                                                                                  

                                                                                  (where I've used the synonym OneOfTrue to make things easier to read: type OneOfTrue t ts = OneOf t ts :~: (() :: Constraint)).

                                                                                  If this can be implemented then you should be good to go, although I would probably still prefer to use OneOf' when possible.

                                                                                  It's worth noting that something like OneOf' is a relatively common construct in dependently typed languages: There's an Agda example here, an Idris example here and a similar thing in Coq here. Each of these has value-level content in the same way that OneOf' does.

                                                                                  Item could be rewritten to use OneOf' like this:

                                                                                  type Item' :: Cat -> SubCat -> Type
                                                                                  data Item' cat subCat where
                                                                                      Item' :: OneOf' subCat (ValidSubCats cat) -> Item' cat subCat
                                                                                  

                                                                                  and there is a corresponding rewrite for makeItem to use Item'.

                                                                                  Why the original OneOf is tricky and OneOf' is less tricky

                                                                                  It is often difficult to work with something like OneOf. One reason is that Haskell allows type families which can get "stuck". This prevents can prevent some type-level "reductions" and we do not have things like canonical forms.

                                                                                  For example, consider this definition which could be useful in dealing with something like type-level lists passed to a OneOf:

                                                                                  listDecideNilCons :: forall ts. Either (ts :~: '[]) (IsCons ts)
                                                                                  listDecideNilCons = ...
                                                                                  
                                                                                  data IsCons a where
                                                                                    MkIsCons :: forall t ts. IsCons (t ': ts)
                                                                                  

                                                                                  listDecideNilCons would just tell you that a type-level list is either a nil or a cons, which seems pretty reasonable and it would be a handy fact to make use of. In fact, I suspect that it would be necessary to be able to implement listDecideNilCons or something similar to it in order to be able to implement convertOneOf. I suspect even more strongly that it is necessary to implement the other direction of the conversion.

                                                                                  However, the existence of stuck type families is sufficient to show that listDecideNilCons cannot be implemented. Consider:

                                                                                  type family Sticky (b :: Bool) :: [Int] where
                                                                                    Sticky True = '[]
                                                                                  
                                                                                  example :: Either ((Sticky False) :~: '[]) (IsCons (Sticky False))
                                                                                  example = listDecideNilCons
                                                                                  

                                                                                  This code type-checks. What should the value of example be? Since Sticky False cannot be reduced any further, there isn't a value for example that would make sense.

                                                                                  Note that if we also have value-level information, like we do with OneOf', we do not run into this issue for two reasons: Stuck types are not an issue because we can control which specific "shapes" (like '[] and ... ': ...) we are allowed to take in and we can use the proof values when we construct proofs of new things.

                                                                                  For example, in the case of OneOf', it ensures that the type-level list will have the "shape" ... ': .... In the function oneOf', we are using the proof value from the recursive call oneOf' x ys to build a larger proof.

                                                                                  In the original oneOf function, we cannot make use of the fact that the result of a recursive call will either have a "cons shape" or it will give back Nothing (since the original OneOf doesn't give us this information). However, we must know this to use the result of the recursive call to produce the desired result since the original OneOf requires a "cons shape".

                                                                                  Source https://stackoverflow.com/questions/71816582

                                                                                  QUESTION

                                                                                  Creating new columns based on data in row separated by specific character in R
                                                                                  Asked 2022-Mar-15 at 08:48

                                                                                  I've the following table

                                                                                  Owner Pet Housing_Type A Cats;Dog;Rabbit 3 B Dog;Rabbit 2 C Cats 2 D Cats;Rabbit 3 E Cats;Fish 1

                                                                                  The code is as follows:

                                                                                  Data_Pets = structure(list(Owner = structure(1:5, .Label = c("A", "B", "C", "D",
                                                                                   "E"), class = "factor"), Pets = structure(c(2L, 5L, 1L,4L, 3L), .Label = c("Cats ",
                                                                                   "Cats;Dog;Rabbit", "Cats;Fish","Cats;Rabbit", "Dog;Rabbit"), class = "factor"), 
                                                                                  House_Type = c(3L,2L, 2L, 3L, 1L)), class = "data.frame", row.names = c(NA, -5L))
                                                                                  

                                                                                  Can anyone advise me how I can create new columns based on the data in Pet column by creating a new column for each animal separated by ; to look like the following table?

                                                                                  Owner Cats Dog Rabbit Fish Housing_Type A Y Y Y N 3 B N Y Y N 2 C N Y N N 2 D Y N Y N 3 E Y N N Y 1

                                                                                  Thanks!

                                                                                  ANSWER

                                                                                  Answered 2022-Mar-15 at 08:48

                                                                                  One approach is to define a helper function that matches for a specific animal, then bind the columns to the original frame.

                                                                                  Note that some wrangling is done to get rid of whitespace to identify the unique animals to query.

                                                                                  f <- Vectorize(function(string, match) {
                                                                                    ifelse(grepl(match, string), "Y", "N")
                                                                                  }, c("match"))
                                                                                  
                                                                                  df %>%
                                                                                    bind_cols(
                                                                                      f(df$Pets, unique(unlist(strsplit(trimws(as.character(df$Pets)), ";"))))
                                                                                    )
                                                                                  
                                                                                    Owner            Pets House_Type Cats Dog Rabbit Fish
                                                                                  1     A Cats;Dog;Rabbit          3    Y   Y      Y    N
                                                                                  2     B      Dog;Rabbit          2    N   Y      Y    N
                                                                                  3     C           Cats           2    Y   N      N    N
                                                                                  4     D     Cats;Rabbit          3    Y   N      Y    N
                                                                                  5     E       Cats;Fish          1    Y   N      N    Y
                                                                                  

                                                                                  Or more generalized if you don't know for sure that the separator is ;, and whitespace is present, stringi is useful:

                                                                                  dplyr::bind_cols(
                                                                                    df,
                                                                                    f(df$Pets, unique(unlist(stringi::stri_extract_all_words(df$Pets))))
                                                                                  )
                                                                                  

                                                                                  Source https://stackoverflow.com/questions/71478316

                                                                                  QUESTION

                                                                                  Doobie - lifting arbitrary effect into ConnectionIO CE3
                                                                                  Asked 2022-Feb-24 at 20:03

                                                                                  I am trying to migrate project from cats-effect 2 to cats-effect 3, i am using doobie for interacting with database. Previously i could lift ConnectionIO to IO as it was described, but with the upgrade i didn't find any implementation of LiftIO[ConnectionIO], how can be same achieved with CE3?

                                                                                  ANSWER

                                                                                  Answered 2022-Feb-21 at 20:03

                                                                                  I found the way to achieve it by

                                                                                  def f()(implicit liftToConnectionIO: FunctionK[IO, ConnectionIO]): IO[Unit] = IO.unit
                                                                                  implicit val liftToConnectionIO = WeakAsync.liftK[IO, ConnectionIO]
                                                                                  liftToConnectionIO.use(implicit lift => f())
                                                                                  

                                                                                  Source https://stackoverflow.com/questions/71212284

                                                                                  QUESTION

                                                                                  Extract data frames from nested list
                                                                                  Asked 2021-Dec-29 at 00:06

                                                                                  I have a nested list of lists which contains some data frames. However, the data frames can appear at any level in the list. What I want to end up with is a flat list, i.e. just one level, where each element is only the data frames, with all other things discarded.

                                                                                  I have come up with a solution for this, but it looks very clunky and I am sure there ought to be a more elegant solution.

                                                                                  Importantly, I'm looking for something in base R, that can extract data frames at any level inside the nested list. I have tried unlist() and dabbled with rapply() but somehow not found a satisfying solution.

                                                                                  Example code follows: an example list, what I am actually trying to achieve, and my own solution which I am not very happy with. Thanks for any help!

                                                                                  # extract dfs from list
                                                                                  
                                                                                  # example of multi-level list with some dfs in it
                                                                                  # note, dfs could be nested at any level
                                                                                  problem1 <- list(x1 = 1,
                                                                                                x2 = list(
                                                                                                  x3 = "dog",
                                                                                                  x4 = data.frame(cats = c(1, 2),
                                                                                                                 pigs = c(3, 4))
                                                                                                ),
                                                                                                x5 = data.frame(sheep = c(1,2,3),
                                                                                                               goats = c(4,5,6)),
                                                                                                x6 = list(a = 2,
                                                                                                         b = "c"),
                                                                                                x7 = head(cars,5))
                                                                                  
                                                                                  # want to end up with flat list like this (names format is optional)
                                                                                  result1 <- list(x2.x4 = data.frame(cats = c(1, 2),
                                                                                                                     pigs = c(3, 4)),
                                                                                                  x5 = data.frame(sheep = c(1,2,3),
                                                                                                                  goats = c(4,5,6)),
                                                                                                  x7 = head(cars,5))
                                                                                  
                                                                                  # my solution (not very satisfactory)
                                                                                  
                                                                                  exit_loop <- FALSE
                                                                                  while(exit_loop == FALSE){
                                                                                    # find dfs (logical)
                                                                                    idfs <- sapply(problem1, is.data.frame)
                                                                                    # check if all data frames
                                                                                    exit_loop <- all(idfs)
                                                                                    # remove anything not df or list
                                                                                    problem1 <- problem1[idfs | sapply(problem1, is.list)]
                                                                                    # find dfs again (logical)
                                                                                    idfs <- sapply(problem1, is.data.frame)
                                                                                    # unlist only the non-df part
                                                                                    problem1 <- c(problem1[idfs], unlist(problem1[!idfs], recursive = FALSE))
                                                                                  
                                                                                  }
                                                                                  
                                                                                  

                                                                                  ANSWER

                                                                                  Answered 2021-Dec-28 at 22:13

                                                                                  Maybe consider a simple recursive function like this

                                                                                  find_df <- function(x) {
                                                                                    if (is.data.frame(x))
                                                                                      return(list(x))
                                                                                    if (!is.list(x))
                                                                                      return(NULL)
                                                                                    unlist(lapply(x, find_df), FALSE)
                                                                                  }
                                                                                  

                                                                                  Results

                                                                                  > find_df(problem1)
                                                                                  $x2.x4
                                                                                    cats pigs
                                                                                  1    1    3
                                                                                  2    2    4
                                                                                  
                                                                                  $x5
                                                                                    sheep goats
                                                                                  1     1     4
                                                                                  2     2     5
                                                                                  3     3     6
                                                                                  
                                                                                  $x7
                                                                                    speed dist
                                                                                  1     4    2
                                                                                  2     4   10
                                                                                  3     7    4
                                                                                  4     7   22
                                                                                  5     8   16
                                                                                  

                                                                                  Source https://stackoverflow.com/questions/70512869

                                                                                  QUESTION

                                                                                  How do I implement two methods from two interfaces with the same name?
                                                                                  Asked 2021-Dec-21 at 14:53

                                                                                  I'm having some trouble using method resolution clause in Delphi 10.4.

                                                                                  Say I want to create a cat and a dog repository. In this case the TAnimalRepository has both cats and dogs, so I would like to implement both the cat and dog interfaces in that class.

                                                                                  Example:

                                                                                  IRepositoryBase = Interface
                                                                                      ['{776B3383-AF6E-44F7-BF32-1ACCF9A6C964}']
                                                                                      function GetAll(items: TList; out errMsg: String): Boolean;
                                                                                  End;
                                                                                  
                                                                                  TCat = class
                                                                                  end;
                                                                                  
                                                                                  ICatRepository = Interface(IRepositoryBase)
                                                                                      ['{C37CF989-E069-450B-8937-E46F6BFA66E9}']
                                                                                      function GetAll(items: TList; out errMsg: String): Boolean;
                                                                                  End;
                                                                                  
                                                                                  TDog = class
                                                                                  end;
                                                                                  
                                                                                  IDogRepository = Interface(IRepositoryBase)
                                                                                      ['{56B28463-0007-497E-8015-D794873328FF}']
                                                                                      function GetAll(items: TList; out errMsg: String): Boolean;
                                                                                  End;
                                                                                  
                                                                                  TAnimalRepository = class(TInterfacedObject, ICatRepository, IDogRepository)
                                                                                      function ICatRepository.GetAll = GetAllCats;
                                                                                      function IDogRepository.GetAll = GetAllDogs;
                                                                                  public
                                                                                      function GetAllCats(items: TList; out errMsg: String): Boolean;
                                                                                      function GetAllDogs(items: TList; out errMsg: String): Boolean;
                                                                                  end;
                                                                                  

                                                                                  Since we have two different methods with the same name, I have tried to use method resolution clause as described here: https://docwiki.embarcadero.com/RADStudio/Sydney/en/Implementing_Interfaces

                                                                                  function ICatRepository.GetAll = GetAllCats;
                                                                                  function IDogRepository.GetAll = GetAllDogs;
                                                                                  

                                                                                  But when I try to compile the above code, it fails with:

                                                                                  [dcc32 Error] MethodResolutionExample.dpr(33): E2291 Missing implementation of interface method MethodResolutionExample.IRepositoryBase.GetAll
                                                                                  
                                                                                  [dcc32 Error] MethodResolutionExample.dpr(33): E2291 Missing implementation of interface method MethodResolutionExample.IRepositoryBase.GetAll
                                                                                  

                                                                                  Then I thought, why not try to add a method resolution for their inherited interface IRepositoryBase as well, like this:

                                                                                  TAnimalRepository = class(TInterfacedObject, ICatRepository, IDogRepository)
                                                                                      function ICatRepository.GetAll = GetAllCats;
                                                                                      function IRepositoryBase.GetAll = GetAllCats;  // <--- This
                                                                                      function IDogRepository.GetAll = GetAllDogs;
                                                                                      function IRepositoryBase.GetAll = GetAllDogs;  // <--- This
                                                                                  public
                                                                                      function GetAllCats(items: TList; out errMsg: String): Boolean;
                                                                                      function GetAllDogs(items: TList; out errMsg: String): Boolean;
                                                                                  end;
                                                                                  

                                                                                  But now it gets funky. It looks like the compiler can't handle generics in the method resolution clause, because I get a lot of parsing errors now, beginning with:

                                                                                  [dcc32 Error] MethodResolutionExample.dpr(35): E2023 Function needs result type
                                                                                  

                                                                                  It complains about this line:

                                                                                  function IRepositoryBase.GetAll = GetAllCats;
                                                                                  

                                                                                  What am I doing wrong? Do I really have to split my TAnimalRepository up in two different classes?

                                                                                  Thanks in advance.

                                                                                  Oh, one important note. I can get it to work, if my ICatRepository and IDogRepository doesn't inherit from IRepositoryBase. But in my use case, I would like them to inherit from the base class.

                                                                                  ANSWER

                                                                                  Answered 2021-Dec-21 at 14:53

                                                                                  You need to get rid of the additional declarations of GetAll in ICatRepository and IDogRepository. If you just leave the GUID in these interfaces all works as expected.

                                                                                  type
                                                                                    IRepositoryBase = interface
                                                                                      ['{776B3383-AF6E-44F7-BF32-1ACCF9A6C964}']
                                                                                      function GetAll(items: TList; out errMsg: string): Boolean;
                                                                                    end;
                                                                                  
                                                                                    TCat = class
                                                                                    end;
                                                                                  
                                                                                    ICatRepository = interface(IRepositoryBase)
                                                                                      ['{C37CF989-E069-450B-8937-E46F6BFA66E9}']
                                                                                    end;
                                                                                  
                                                                                    TDog = class
                                                                                    end;
                                                                                  
                                                                                    IDogRepository = interface(IRepositoryBase)
                                                                                      ['{56B28463-0007-497E-8015-D794873328FF}']
                                                                                    end;
                                                                                  
                                                                                    TAnimalRepository = class(TInterfacedObject, ICatRepository, IDogRepository)
                                                                                      function ICatRepository.GetAll = GetAllCats;
                                                                                      function IDogRepository.GetAll = GetAllDogs;
                                                                                    public
                                                                                      function GetAllCats(items: TList; out errMsg: string): Boolean;
                                                                                      function GetAllDogs(items: TList; out errMsg: string): Boolean;
                                                                                    end;
                                                                                  

                                                                                  The additional GetAll declarations don't just replace the generic one, but add another method to the interface instead.

                                                                                  Source https://stackoverflow.com/questions/70436810

                                                                                  QUESTION

                                                                                  Replace NA in DataFrame for multiple columns with mean per country
                                                                                  Asked 2021-Dec-12 at 16:33

                                                                                  I want to replace NA values with the mean of other column with the same year.

                                                                                  Note:
                                                                                  To replace NA values for Canada data, I want to use only the mean of Canada, not the mean from the whole dataset of course.

                                                                                  Here's a sample dataframe filled with random numbers. And some NA how i find them in my dataframe:

                                                                                  Country Inhabitants Year Area Cats Dogs Canada 38 000 000 2021 4 32 21 Canada 37 000 000 2020 4 NA 21 Canada 36 000 000 2019 3 32 21 Canada NA 2018 2 32 21 Canada 34 000 000 2017 NA 32 21 Canada 35 000 000 2016 3 32 NA Brazil 212 000 000 2021 5 32 21 Brazil 211 000 000 2020 4 NA 21 Brazil 210 000 000 2019 NA 32 21 Brazil 209 000 000 2018 4 32 21 Brazil NA 2017 2 32 21 Brazil 207 000 000 2016 4 32 NA

                                                                                  What's the easiest way with pandas to replace those NA with the mean values of the other years? And is it possible to write a code for which it is possible to go through every NA and replace them (Inhabitants, Area, Cats, Dogs at once)?

                                                                                  ANSWER

                                                                                  Answered 2021-Dec-12 at 15:07

                                                                                  Note Example is based on your additional data source from the comments

                                                                                  Replacing the NA-Values for multiple columns with mean() you can combine the following three methods:

                                                                                  • fillna() (Iterating per column axis should be 0, which is default value of fillna())
                                                                                  • groupby()
                                                                                  • transform()
                                                                                  Create data frame from your example:
                                                                                  df = pd.read_excel('https://happiness-report.s3.amazonaws.com/2021/DataPanelWHR2021C2.xls')
                                                                                  
                                                                                  Country name year Life Ladder Log GDP per capita Social support Healthy life expectancy at birth Freedom to make life choices Generosity Perceptions of corruption Positive affect Negative affect Canada 2005 7.41805 10.6518 0.961552 71.3 0.957306 0.25623 0.502681 0.838544 0.233278 Canada 2007 7.48175 10.7392 nan 71.66 0.930341 0.249479 0.405608 0.871604 0.25681 Canada 2008 7.4856 10.7384 0.938707 71.84 0.926315 0.261585 0.369588 0.89022 0.202175 Canada 2009 7.48782 10.6972 0.942845 72.02 0.915058 0.246217 0.412622 0.867433 0.247633 Canada 2010 7.65035 10.7165 0.953765 72.2 0.933949 0.230451 0.41266 0.878868 0.233113 Call fillna() and iterate over all columns grouped by name of country:
                                                                                  df = df.fillna(df.groupby('Country name').transform('mean'))
                                                                                  
                                                                                  Check your result for Canada:
                                                                                  df[df['Country name'] == 'Canada']
                                                                                  
                                                                                  Country name year Life Ladder Log GDP per capita Social support Healthy life expectancy at birth Freedom to make life choices Generosity Perceptions of corruption Positive affect Negative affect Canada 2005 7.41805 10.6518 0.961552 71.3 0.957306 0.25623 0.502681 0.838544 0.233278 Canada 2007 7.48175 10.7392 0.93547 71.66 0.930341 0.249479 0.405608 0.871604 0.25681 Canada 2008 7.4856 10.7384 0.938707 71.84 0.926315 0.261585 0.369588 0.89022 0.202175 Canada 2009 7.48782 10.6972 0.942845 72.02 0.915058 0.246217 0.412622 0.867433 0.247633 Canada 2010 7.65035 10.7165 0.953765 72.2 0.933949 0.230451 0.41266 0.878868 0.233113

                                                                                  Source https://stackoverflow.com/questions/70324164

                                                                                  QUESTION

                                                                                  Testing a NestJS Service that uses Prisma without actually accessing the database
                                                                                  Asked 2021-Dec-06 at 16:43

                                                                                  Most examples I've seen of how to test a Prisma-injected NestJS Service (e.g. prisma-sample in testing-nestjs) are for "end to end" testing. They actually access the database, performing actual queries and then rolling back the results if necessary.

                                                                                  For my current needs, I want to implement lower-level "integration" testing.

                                                                                  As part of this, I want to remove Prisma from the equation. I want the focus to be on my service's functionality instead of the state of data within the database and Prisma's ability to return it.

                                                                                  One big win of this approach is that it obviates the need to craft "setup" queries and "teardown"/reset operations for specific tests. Instead, I'd like to simply manually specify what we would expect Prisma to return.

                                                                                  In an environment consisting of NestJS, Prisma, and Jest, how should I accomplish this?

                                                                                  UPDATE: The author of the testing-nestjs project pointed out in the comments that the project does have an example of database mocking. It looks nice! Others may still be interested in checking out the Gist that I've linked to as it includes some other useful functionality.

                                                                                  ANSWER

                                                                                  Answered 2021-Dec-04 at 19:40

                                                                                  To get a reference to your service's prisma instance, use:

                                                                                  prisma = module.get(PrismaService)
                                                                                  

                                                                                  Then, assuming your function calls prisma.name.findMany(), you can use jest.fn().mockReturnValueOnce() to mock (manually specify) Prisma's next return value:

                                                                                  prisma.name.findMany = jest.fn().mockReturnValueOnce([
                                                                                      { id: 0, name: 'developer' },
                                                                                      { id: 10, name: 'architect' },
                                                                                      { id: 13, name: 'dog walker' }
                                                                                  ]);
                                                                                  

                                                                                  (Of course, you would change prisma.name.findMany in the code above to match whatever function you're calling.)

                                                                                  Then, call the function on your Service that you're testing. For example:

                                                                                  expect(await service.getFirstJob("steve")).toBe('developer');
                                                                                  

                                                                                  Source https://stackoverflow.com/questions/70228893

                                                                                  QUESTION

                                                                                  How to make smoother borders using Fragment shader in OpenGL?
                                                                                  Asked 2021-Nov-28 at 16:45

                                                                                  I have been trying to draw border of an Image with transparent background using OpenGL in Android. I am using Fragment Shader & Vertex Shader. (From the GPUImage Library)

                                                                                  Below I have added Fig. A & Fig B.

                                                                                  Fig A.

                                                                                  Fig B.

                                                                                  I have achieved Fig A. With the customised Fragment Shader. But Unable to make the border smoother as in Fig B. I am attaching the Shader code that I have used (to achieve rough border). Can someone here help me on how to make the border smoother?

                                                                                  Here is my Vertex Shader :

                                                                                      attribute vec4 position;
                                                                                      attribute vec4 inputTextureCoordinate;        
                                                                                      varying vec2 textureCoordinate;
                                                                                      
                                                                                      void main()
                                                                                      {
                                                                                          gl_Position = position;
                                                                                          textureCoordinate = inputTextureCoordinate.xy;
                                                                                      }
                                                                                  

                                                                                  Here is my Fragment Shader :

                                                                                  I have calculated 8 pixels around the current pixel. If any one pixel of those 8 is opaque(having alpha greater than 0.4), It it drawn as a border color.

                                                                                                  precision mediump float;
                                                                                                  uniform sampler2D inputImageTexture;
                                                                                                  varying vec2 textureCoordinate;
                                                                                                  uniform lowp float thickness;
                                                                                                  uniform lowp vec4 color;
                                                                                  
                                                                                                  void main() {
                                                                                                      float x = textureCoordinate.x;
                                                                                                      float y = textureCoordinate.y;
                                                                                                      vec4 current = texture2D(inputImageTexture, vec2(x,y));
                                                                                  
                                                                                                      if ( current.a != 1.0 ) {
                                                                                                          float offset = thickness * 0.5;
                                                                                                          
                                                                                                          vec4 top = texture2D(inputImageTexture, vec2(x, y - offset));
                                                                                                          vec4 topRight = texture2D(inputImageTexture, vec2(x + offset,y - offset));
                                                                                                          vec4 topLeft = texture2D(inputImageTexture, vec2(x - offset, y - offset));
                                                                                                          vec4 right = texture2D(inputImageTexture, vec2(x + offset, y ));
                                                                                                          vec4 bottom = texture2D(inputImageTexture, vec2(x , y + offset));
                                                                                                          vec4 bottomLeft  = texture2D(inputImageTexture, vec2(x - offset, y + offset));
                                                                                                          vec4 bottomRight = texture2D(inputImageTexture, vec2(x + offset, y + offset));
                                                                                                          vec4 left = texture2D(inputImageTexture, vec2(x - offset, y ));
                                                                                                          
                                                                                                          if ( top.a > 0.4 || bottom.a > 0.4 || left.a > 0.4 || right.a > 0.4 || topLeft.a > 0.4 || topRight.a > 0.4 || bottomLeft.a > 0.4 || bottomRight.a > 0.4 ) {
                                                                                                               if (current.a != 0.0) {
                                                                                                                   current = mix(color , current , current.a);
                                                                                                               } else {
                                                                                                                   current = color;
                                                                                                               }
                                                                                                          }
                                                                                                      }
                                                                                                      
                                                                                                      gl_FragColor = current;
                                                                                                  }
                                                                                  

                                                                                  ANSWER

                                                                                  Answered 2021-Nov-28 at 16:45

                                                                                  In my filters, the smoothness is achieved by a simple boxblur on the border.. You have decided that alpha > 0.4 is a border. The value of alpha between 0-0.4 in surrounding pixels gives an edge. Just blur this edge with a 3x3 window to get the smooth edge.

                                                                                                      if ( current.a != 1.0 ) {
                                                                                                      // other processing
                                                                                                      
                                                                                                      if (current.a > 0.4) {
                                                                                                          if ( (top.a < 0.4 || bottom.a < 0.4 || left.a < 0.4 || right.a < 0.4 
                                                                                                               || topLeft.a < 0.4 || topRight.a < 0.4 || bottomLeft.a < 0.4 || bottomRight.a < 0.4 ) 
                                                                                                          {
                                                                                                               // Implement 3x3 box blur here
                                                                                                               
                                                                                                          }
                                                                                                      }
                                                                                      }
                                                                                  

                                                                                  You need to tweak which edge pixels you blur. The basic issue is that it drops from an opaque to a transparent pixel - what you need is a gradual transition.

                                                                                  Another options is quick anti-aliasing. From my comment below - Scale up 200% and then scale down 50% to original method. Use nearest neighbour scaling. This technique is used for smooth edges on text sometimes.

                                                                                  Source https://stackoverflow.com/questions/69481402

                                                                                  QUESTION

                                                                                  How to implement horizontal scrolling of tiles in MUI GridList?
                                                                                  Asked 2021-Oct-16 at 18:29

                                                                                  This is my JS page where I need to implement the GridList component to show multiple tiles and is scrollable horizontally after list size crosses screen limits.

                                                                                  import React,{ useState} from "react";
                                                                                  import Header from "../../common/header/Header";
                                                                                  import "./Home.css";
                                                                                  import { GridList, GridListTile, GridListTileBar} from "@material-ui/core";
                                                                                  
                                                                                  const images = [
                                                                                      { thumbnail: { uri: 'https://lorempixel.com/200/200/animals',name:'animals'}},
                                                                                      { thumbnail: { uri: 'https://lorempixel.com/200/200/city'  ,name:'city'}},
                                                                                      { thumbnail: { uri: 'https://lorempixel.com/200/200/city'  ,name:'city'}},
                                                                                      { thumbnail: { uri: 'https://lorempixel.com/200/200/city'  ,name:'city'}},
                                                                                      { thumbnail: { uri: 'https://lorempixel.com/200/200/nature'  ,name:'nature'} },
                                                                                      { thumbnail: { uri: 'https://lorempixel.com/200/200/cats'  ,name:'cats'} },
                                                                                      { thumbnail: { uri: 'https://lorempixel.com/200/200/cats'  ,name:'cats'} },
                                                                                      { thumbnail: { uri: 'https://lorempixel.com/200/200/cats'  ,name:'cats'} },
                                                                                    ];
                                                                                  
                                                                                  export default function Home() {
                                                                                    return (
                                                                                      <>
                                                                                        
                                                                                        Upcoming Movies
                                                                                          
                                                                                              {images.map((image) => (
                                                                                              
                                                                                                  
                                                                                                  
                                                                                              
                                                                                              ))}
                                                                                          
                                                                                      
                                                                                    );
                                                                                  }
                                                                                  

                                                                                  ANSWER

                                                                                  Answered 2021-Oct-16 at 18:28

                                                                                  Note: In the newer versions of MUI, GridList's been changed to ImageList, the code below uses the latest API.

                                                                                  You can fill the column instead of row by using the code below:

                                                                                  
                                                                                    {images.map((image) => (
                                                                                      
                                                                                        
                                                                                        
                                                                                      
                                                                                    ))}
                                                                                  
                                                                                  
                                                                                  • gridAutoFlow: 'column': Tell the grid to create another column if there is no space left instead of going to the next row.
                                                                                  • gridTemplateColumns: 'repeat(auto-fill, minmax(160px, 1fr))': Set the column min and max width, min is 160px, if there is more than enough space (no need for horizontal scrollbar), set each column width equally.
                                                                                  • gridAutoColumns: 'minmax(160px, 1fr)': Same as above but for the columns outside of the viewport.
                                                                                  Live Demo

                                                                                  V5

                                                                                  V4

                                                                                  References

                                                                                  Source https://stackoverflow.com/questions/69597992

                                                                                  QUESTION

                                                                                  Cats auto derived with Seq
                                                                                  Asked 2021-Oct-16 at 13:46

                                                                                  I want to define equality for some type that can be part of other objects or collections using cats/kitten. I don't want to have to define the equality for every other class. For example:

                                                                                  import cats.Eq
                                                                                  
                                                                                  case class Foo(a: Int, bar: Bar)
                                                                                  
                                                                                  case class Bar(b: Int)
                                                                                  
                                                                                  object BarEq {
                                                                                    implicit val barEq: Eq[Bar] = Eq.instance[Bar] {
                                                                                      (b1, b2) => b1.b +1 == b2.b
                                                                                    }
                                                                                  }
                                                                                  

                                                                                  and then a test defined as

                                                                                  import cats.derived.auto.eq._
                                                                                  
                                                                                  
                                                                                  class BarEqTest extends FlatSpec with cats.tests.StrictCatsEquality {
                                                                                    import BarEq._
                                                                                  
                                                                                    "bareq" should {
                                                                                      "work" in {
                                                                                        Foo(1, Bar(1)) should ===(Foo(1, Bar(2)))
                                                                                        Bar(1) should ===(Bar(2))
                                                                                        Some(Foo(1, Bar(1))) should ===(Some(Foo(1, Bar(2))))
                                                                                      }
                                                                                    }
                                                                                  }
                                                                                  
                                                                                  

                                                                                  this works fine, but if I try to add the following test case

                                                                                  Seq(Foo(1, Bar(1))) should ===(Seq(Foo(1, Bar(2))))
                                                                                  

                                                                                  I get

                                                                                  [Error] types Seq[Foo] and Seq[Foo] do not adhere to the type constraint selected for the === and !== operators; the missing implicit parameter is of type org.scalactic.CanEqual[Seq[Foo],Seq[Foo]]
                                                                                  one error found
                                                                                  

                                                                                  How come the auto derived eq works with Option but not Seq, and how can I make it work? I tried to add import cats.instances.seq._ but that did not work either.

                                                                                  ANSWER

                                                                                  Answered 2021-Oct-16 at 13:46

                                                                                  Cats defines an instance of Eq for scala.collection.immutable.Seq, not for generic scala.collection.Seq (or moreover scala.collection.mutable.Seq)

                                                                                  import scala.collection.immutable.{BitSet, Queue, Seq, SortedMap, SortedSet}
                                                                                  
                                                                                  private[kernel] trait EqInstances0 {
                                                                                    implicit def catsKernelEqForSeq[A: Eq]: Eq[Seq[A]] = cats.kernel.instances.seq.catsKernelStdEqForSeq[A]
                                                                                  }
                                                                                  

                                                                                  https://github.com/typelevel/cats/blob/main/kernel/src/main/scala/cats/kernel/Eq.scala#L283-L285

                                                                                  Starting from Scala 2.13.0 scala.Seq is scala.collection.immutable.Seq. But in Scala 2.12.x scala.Seq is scala.collection.Seq.

                                                                                  https://github.com/scala/scala/releases/tag/v2.13.0

                                                                                  So in Scala 2.12 import correct collection type

                                                                                  import scala.collection.immutable.Seq
                                                                                  Seq(Foo(1, Bar(1))) === Seq(Foo(1, Bar(2))) // true
                                                                                  

                                                                                  or define your own instance of Eq for necessary collections

                                                                                  import cats.kernel.instances.StaticMethods
                                                                                  
                                                                                  implicit def genericSeqEq[A: Eq]: Eq[collection.Seq[A]] = new Eq[collection.Seq[A]] {
                                                                                    override def eqv(xs: collection.Seq[A], ys: collection.Seq[A]): Boolean =
                                                                                      if (xs eq ys) true
                                                                                      else StaticMethods.iteratorEq(xs.iterator, ys.iterator)
                                                                                  }
                                                                                  
                                                                                  Seq(Foo(1, Bar(1))) === Seq(Foo(1, Bar(2))) // true
                                                                                  

                                                                                  Source https://stackoverflow.com/questions/69591709

                                                                                  Community Discussions, Code Snippets contain sources that include Stack Exchange Network

                                                                                  Vulnerabilities

                                                                                  No vulnerabilities reported

                                                                                  Install cats

                                                                                  CATS is bundled both as an executable JAR or a native binary. The native binaries do not need Java installed.
                                                                                  You can build CATS from sources on you local box. You need Java 11+. Maven is already bundled.
                                                                                  When using the native binaries (not the uberjar) there might be issues when using dynamic values in the CATS files. This is due to the fact that GraalVM only bundles whatever can discover at compile time. The following classes are currently supported:.

                                                                                  Support

                                                                                  https://github.com/hashicorp/vault/issues/13274https://github.com/hashicorp/vault/issues/13273https://github.com/hashicorp/vault/issues/13225https://github.com/hashicorp/vault/issues/13232
                                                                                  Find more information at:
                                                                                  Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
                                                                                  Find more libraries
                                                                                  Explore Kits - Develop, implement, customize Projects, Custom Functions and Applications with kandi kits​
                                                                                  Save this library and start creating your kit

                                                                                  Share this Page

                                                                                  share link

                                                                                  Explore Related Topics

                                                                                  Consider Popular Java Libraries

                                                                                  CS-Notes

                                                                                  by CyC2018

                                                                                  JavaGuide

                                                                                  by Snailclimb

                                                                                  LeetCodeAnimation

                                                                                  by MisterBooo

                                                                                  spring-boot

                                                                                  by spring-projects

                                                                                  Try Top Libraries by Endava

                                                                                  bee-q

                                                                                  by EndavaTypeScript

                                                                                  homebrew-tap

                                                                                  by EndavaRuby

                                                                                  Compare Java Libraries with Highest Support

                                                                                  elasticsearch

                                                                                  by elastic

                                                                                  spring-boot

                                                                                  by spring-projects

                                                                                  bazel

                                                                                  by bazelbuild

                                                                                  guava

                                                                                  by google

                                                                                  fastjson

                                                                                  by alibaba

                                                                                  Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
                                                                                  Find more libraries
                                                                                  Explore Kits - Develop, implement, customize Projects, Custom Functions and Applications with kandi kits​
                                                                                  Save this library and start creating your kit